|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Convert form's string variable to numeric?
Hi ppl,
When I send via form to script the "4+4" expression script got it as string variable. Is there any way to convert form's string variable to numeric variable? P.S. Don't tell me to use with intval() function cause: $string="4+4"; /*For experiment*/ $var=intval($string); print $var; /* Print: 4, cause for intval() "+" is not valid charecter*/ |
|
#2
|
|||
|
|||
|
RE: Convert form's string variable to numeric?
How about this:
<? $string="4+4"; $total=intval($string[0]) + intval($string[2]); print $total; ?> of course that only works with one digit numbers...try this for something that works with bigger numbers: <? $string="4+4"; $strings = explode('+',$string); $total=intval($strings[0]) + intval($strings[1]); print $total; ?> |
|
#3
|
|||
|
|||
|
RE: Convert form's string variable to numeric?
I found better solution:
$str = "4+4"; eval("$var = $str;"); print $var; |
|
#4
|
|||
|
|||
|
RE: Convert form's string variable to numeric?
Somthing wrong with your forum:
I tried to post: eval("$var = $str;"); *Slash disappear before $var! |
|
#5
|
|||
|
|||
|
RE: Convert form's string variable to numeric?
try using three slashes - you escape the quotes and then escape the escape character... for example "$var" |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Convert form's string variable to numeric? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|