String to characters and numbers

Is there a way to turn the addition, subtraction, multiplication and division characters into a string into the actual addition, subtraction, multiplication and division characters, as well as the numbers inside the string, to the actual numbers? Thus, instead of characters acting as part of a string, they will act the same as outside the string, and the same for numbers. Is there a function for this?

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

The required result:

$result = 1+1-1*1/1 = 1;
-1
source share
1 answer

Assuming you are outputting a browser,

รท ÷

ร— ×

and I hope you can find and subtract yourself: P

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

+1
source

Source: https://habr.com/ru/post/1609548/


All Articles