String to symbols and numbers [duplicate]

佐手、 提交于 2019-12-25 18:36:45

问题


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";

Needed Result:

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

回答1:


Assuming you're outputting to the browser,

÷ is ÷

× is ×

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

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



来源:https://stackoverflow.com/questions/32855791/string-to-symbols-and-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!