Re: PREG_REPLACE, with array error...

From: Date: Mon, 30 Oct 2000 22:07:12 +0000
Subject: Re: PREG_REPLACE, with array error...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22759@lists.php.net to get a copy of this message
To replace whole words only, use a word boundary like so: /\be\b/ Roy Nasser wrote: > > how would it be? > > somthing like: > > "/e/W"? > > > -----Original Message----- > > From: Lars Torben Wilson [mailto:torben@pinc.com] > > Sent: Monday, October 30, 2000 7:36 PM > > To: Roy Nasser > > Cc: Php (E-mail) > > Subject: Re: [PHP] PREG_REPLACE, with array error... > > > > > > 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| > > +----------------------------------------------------------------+ > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

« previous php.general (#22759) next »