Jump to content

Is there a function that......


boney alex

Recommended Posts

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/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.