Page 1 of 1

Typecasting problems

Posted: Wed Jul 16, 2008 5:23 am
by shiznatix
I have this string. When I var_dump() the string I get this:
string(10) "174"
but I need to use this string as an int in a math problem. I have tried many things but nothing has worked. Here is what I have tried and what it outputs to:

Code: Select all

 
var_dump($matches[0]);//string(10) "174" 
echo '<br>';
var_dump(intval($matches[0]));//int(0) 
echo '<br>';
var_dump((int)$matches[0]);//int(0) 
die();
 
Soooo... how do I get this string to be int(174)?

Re: Typecasting problems

Posted: Wed Jul 16, 2008 5:35 am
by dml
That's strange, the var_dump indicates a string length of 10. Can you do a bin2hex on the string to see what's really there?

Re: Typecasting problems

Posted: Wed Jul 16, 2008 5:59 am
by shiznatix
bin2hex gives me:
string(20) "3c4d3e3137343c2f4d3e"
Edit: arg, stupid me. The regex I am using to get the number out as getting it from between a <M> tag and the tags were still there and thus when you cast <M>174</M> into an int it just says "no" and gives you 0. Blah. Thanks for the hex idea though, didn't think of that