Re: PREG_REPLACE, with array error...

From: Date: Mon, 30 Oct 2000 21:36:08 +0000
Subject: Re: PREG_REPLACE, with array error...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22753@lists.php.net to get a copy of this message
Roy Nasser writes: > Any ideas why the following code doesnt work? I get "Warning: Delimiter must > not be alphanumeric or backslash in /home/httpd/html/pre2000/answer.php on > line 168", this is the line with the first preg_replace statement.... > > <? > $q = " ".$q; > $remove = array ( > "o", > "quando", > "porque", > "do", [snip] > "é", > "e", > "a", > "de", > "vez" > ); > > $q = preg_replace($remove,"",$q); > $q = ereg_replace(" ","",$q); > echo $q; > > ?> You've forgotten the PCRE delimiters around the expressions; they should be something like this: "/é/", "/e/", "/a/", "/de/", Just a small warning, though--the above will remove, for instance, all instances of the letters o, e, etc from the $q string, even if they occur inside a word or something like that. This may be what you want, but if not, you should use \w or \W or something (I forget which) to ensure that only whole words are matched. Good luck, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#22753) next »