1

If i've a string like this

((((((4,50*0,86)*52500*1,0016)+3800)/52500)*2,2046)*1,05) 

how can i do the operation for obtaning the total result?

Thank You

5
  • 2
    Be very careful using user input with eval though Commented Aug 6, 2018 at 17:09
  • What exactly do you mean by a string? Commented Aug 6, 2018 at 17:10
  • @Devon This is true, NEVER eval a user input, but the accepted answer in that question has a split solution, that he can use. Commented Aug 6, 2018 at 17:14
  • @Peon, that split solution only looks to work with a very basic math expression, not what the OP has provided, but there are other answers there that attempt to sanitize. Commented Aug 6, 2018 at 17:17
  • 1
    Solve with this solution! stackoverflow.com/a/27077376/3684020 Thank u Commented Aug 6, 2018 at 17:18

1 Answer 1

0

Maybe your question is a possible duplicate from calculate-math-expression-from-a-string-using-eval

However

if you need to store this in a variable you can do

$string='((((((4,50*0,86)*52500*1,0016)+3800)/52500)*2,2046)*1,05)'; $response=eval('return '.str_replace(',','.',$string.';')); print($response); 

the output is:

9.14027512736 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.