mikesta707 Posted September 24, 2009 Share Posted September 24, 2009 Is there a function that will take the string representation of a number, and return the number it represents? IE if the string was fifteen, it would return 15, etc? Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/ Share on other sites More sharing options...
KevinM1 Posted September 24, 2009 Share Posted September 24, 2009 Is there a function that will take the string representation of a number, and return the number it represents? IE if the string was fifteen, it would return 15, etc? Have you tried casting it to an int? Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/#findComment-924436 Share on other sites More sharing options...
mikesta707 Posted September 24, 2009 Author Share Posted September 24, 2009 Won't work. casting strings to ints only works when you have an int surrounded by quotes, like "2" or "5" or "15", however if you use the word, IE "two", "five", or "fifteen" they get cast to zero (as do all other non integer strings) Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/#findComment-924437 Share on other sites More sharing options...
corbin Posted September 24, 2009 Share Posted September 24, 2009 As far as I know there is not a built in function that does that. Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/#findComment-924438 Share on other sites More sharing options...
Mark Baker Posted September 24, 2009 Share Posted September 24, 2009 There are a number of examples of user-written functions doing this (in various languages) on http://www.php.net Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/#findComment-924448 Share on other sites More sharing options...
KevinM1 Posted September 24, 2009 Share Posted September 24, 2009 Ah, I didn't think you meant the word 'fifteen'. Nope, no built-in function. You'll most likely have to regex the string for a known number value, then return the integer equivalent. Fake EDIT: or use one of the functions found in Mark's link. Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/#findComment-924449 Share on other sites More sharing options...
5kyy8lu3 Posted September 24, 2009 Share Posted September 24, 2009 no built in function to do what you need but you can write a function to do it. i'm sure you can find a function someone else wrote too if you'd rather do it that way. Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/#findComment-924459 Share on other sites More sharing options...
mikesta707 Posted September 25, 2009 Author Share Posted September 25, 2009 thanks mark, the specific function you linked to is the opposite of what I want though hehe, (its ints to words, not words to ints). I was going to write the function but just wanted to know if there was a built in one already. thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/175419-solved-string-represenation-of-number-as-number/#findComment-924529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.