字符串到符号和数字 [英] String to symbols and numbers

查看:96
本文介绍了字符串到符号和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将字符串中的加,减,乘和除符号与字符串中的数字转换为实际的加,减,乘和除符号?因此,代替符号作为字符串的一部分,它们将像在字符串之外一样起作用,数字也一样.有功能吗?

Is there a way to turn the addition, subtraction, multiplication, and division symbols in a string to actual addition, subtraction, multiplication, and division symbols, along with the numbers inside the string to actual numbers? So, instead of the symbols acting as part of the string, they would act as they would outside of the string, and same thing for the numbers. Is there a function to do this?

$ string ="1 + 1-1 * 1/1";

$string = "1+1-1*1/1";

所需结果:

$result = 1+1-1*1/1 = 1;

推荐答案

假设您要输出到浏览器,

Assuming you're outputting to the browser,

÷是÷

×是×

我希望您能够自己计算出加法和减法:P

and I hope you're able to figure out add and subtract on your own :P

$result = "1 + 1 - 1 × 1 ÷ 1 = 1";

这篇关于字符串到符号和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆