garysenter Posted August 9, 2007 Share Posted August 9, 2007 Hello, I have a string that I need to get the numbers out of. The string has both text, and numbers. I want to get rid of the letters, and only keep the numbers. Is this possible?? Please help. Thank you, Gary Quote Link to comment https://forums.phpfreaks.com/topic/64140-getting-numbers-from-a-string/ Share on other sites More sharing options...
lemmin Posted August 9, 2007 Share Posted August 9, 2007 settype() will do that. http://us.php.net/settype Quote Link to comment https://forums.phpfreaks.com/topic/64140-getting-numbers-from-a-string/#findComment-319642 Share on other sites More sharing options...
Orio Posted August 9, 2007 Share Posted August 9, 2007 <?php $str = "dfkjn2424fm9303f3@#$@^%^%&11"; $str = preg_replace("/[^0-9]/", "", $str); echo $str; //Output: 24249303311 ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/64140-getting-numbers-from-a-string/#findComment-319653 Share on other sites More sharing options...
garysenter Posted August 9, 2007 Author Share Posted August 9, 2007 Orio, Thank you very much. That is exactly what I needed. Thank you for the fast response. Quote Link to comment https://forums.phpfreaks.com/topic/64140-getting-numbers-from-a-string/#findComment-319659 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.