[thelist] [PHP] variable conversion tip

Simon Willison cs1spw at bath.ac.uk
Thu Nov 6 19:24:06 CST 2003


Paul Bennett wrote:
> Having trouble getting PHP to treat string data (POST or GET) as a 
> number for a script calculation?
> 
> Multiply the data you are using in calculation by 1 and then use it - 
> this seems to tell PHP to treat the data as numeric
> 
> # sample code
> $duration_in_seconds = ($HTTP_POST_VARS['p_duration'] * 1) * 60;

You can also use casts in PHP to achieve the same effect, like this:

$duration = (int)$HTTP_POST_VARS;

-- 
Simon Willison
Web development weblog: http://simon.incutio.com/



More information about the thelist mailing list