Forum Moderators: coopster

Message Too Old, No Replies

preg_replace problem (again!)

hmmm

         

ahmedtheking

1:16 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, how can i replace these chars " . + -" and any whitespace?

Garfield

8:45 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



You have to 'escape' all characters that are valid regex characters. To do so, just add a backslash in front of the character. For example: \+ or \. Whitespace can be done by /w

Hope it helps

ironik

9:27 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Here's the regex if you need it:

[example]
$text = "some text + any-chars.";
$replacement = preg_replace("/[\+\.-\s]/", "", $text);
echo $replacement; // Returns "sometextanychars"
[/example]

ahmedtheking

10:57 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So wot does "/[\+\.-\s]/" mean? Is there like a comprehensive guide?

ironik

12:09 am on Feb 25, 2005 (gmt 0)

10+ Year Member



See this post:

[webmasterworld.com...]

I put a couple of links in there that should help you