Typecasting problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Typecasting problems

Post 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)?
dml
Forum Contributor
Posts: 133
Joined: Sat Jan 26, 2008 2:20 pm

Re: Typecasting problems

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: Typecasting problems

Post 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
Post Reply