Forum Moderators: coopster
$string = "10/2"; $nums=explode("/",$string); $result=($nums[0] / $nums[1]); It's best to keep numbers and other elements separated, of course. The biggest headache for this type of conversion is that if you were to convert the string as-is to an integer, you'd lose everything from the "/" on.
How strict are you about the operator? Will it always be the same?
$string="10/2"; eval('$string2=$string;'); echo $string2; Returns: 10/2
eval('$string2=10/2;'); echo $string2; Returns: 5
But then ... so does:
$string2=10/2; echo $string2; So you couldn't use a variable for the evaluation without it remaining a string. Hmmm ...