Problem with integers and and strings.
Posted: Mon Jan 09, 2006 10:34 pm
I have a string that I need to be an integer so I can do some math with it.
Heres to code:
I need $pages to be an integer so I can divide it by $div. Ive tried alot of things and cant get it to work.
settype($pages, "integer") only sets $pages to 0
Its got to be something simple I'm missing here.
Any Ideas?
Thanks
Ron
Heres to code:
Code: Select all
if (preg_match("/<td width=\"63%\">[\d]+<\/td>/", $string, $pages)) {
echo "<br>page was found<br>";
print_r($pages); //Returns: Array ( [0] => 143 )
$pages = $pages[0];
echo $pages; //Returns: 143
var_dump($pages); //Returns: string(24) "143"
$div = 40;
var_dump($div); //Returns: int(40)
$numpages = $pages / $div;
var_dump($numpages); //Returns: int(0)
}
else{ echo no page was found<br>";}settype($pages, "integer") only sets $pages to 0
Its got to be something simple I'm missing here.
Any Ideas?
Thanks
Ron