Hi, I wonder if it is possible to have php convert a string to an integer by calculating its value.
Here's what I mean:
(int)"9*8+5"
becomes 9
(php uses the first int in the string)
Is it possible to have this string calculated, so I would get 77?
I think I understand you, you want PHP to do the math instead of thinking 'OK, this is a string.', correct? In that case, you can just eval it as a mathematical equation:
PHP Code:
$math_string = "9*8+5";
eval('$myvar = '. $math_string . ';'); // notice how you don't add quotes around the math_Stirng variable, this way PHP evaluates it as numbers
__________________ Please login or register to view this content. Registration is FREE - Latest Articles: Please login or register to view this content. Registration is FREE , Please login or register to view this content. Registration is FREE