boney alex Posted April 18, 2007 Share Posted April 18, 2007 returns only the numbers within a string?? The reason I ask is because I'm asking the user to enter data such as 1200mm and £9.28. I only want to insert into my database 1200 and 9.28 respectively. Thanks. Link to comment https://forums.phpfreaks.com/topic/47648-is-there-a-function-that/ Share on other sites More sharing options...
trq Posted April 18, 2007 Share Posted April 18, 2007 Take a look at preg_replace. Link to comment https://forums.phpfreaks.com/topic/47648-is-there-a-function-that/#findComment-232693 Share on other sites More sharing options...
boney alex Posted April 18, 2007 Author Share Posted April 18, 2007 Yeah I was looking at that but was struggling to make much sense of it Link to comment https://forums.phpfreaks.com/topic/47648-is-there-a-function-that/#findComment-232717 Share on other sites More sharing options...
Voldemort Posted April 19, 2007 Share Posted April 19, 2007 Use [^\d\.] for what to replace... that will match all digits and periods, and the carat says "if it's not one of these". I guess the literal translation is "If it's not a digit or decimal point" $text = "5h0w 0nly 7h3 d1gi7s. l0l!"; // I hate leetspeak, but it's good for this example $text = preg_replace("/[^\d\.]/" , "" , $text); // Replace everything but digits and decimals with an empty string, aka remove them echo $text; // Should echo 5007317.0 I'd recommend ILoveJackDaniels for a quick lesson on what regular expression do/are, and the manual page thorpe posted for how to use them. http://www.ilovejackdaniels.com/cheat-sheets/regular-expressions-cheat-sheet/ Link to comment https://forums.phpfreaks.com/topic/47648-is-there-a-function-that/#findComment-232762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.