Re: Beginning /< and end of word /> in eregi_replace

From: Date: Fri, 14 Jun 2002 16:57:53 +0000
Subject: Re: Beginning /< and end of word /> in eregi_replace
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-102236@lists.php.net to get a copy of this message
On Fri, 14 Jun 2002, 1LT John W. Holmes wrote: >-You have your answer, just use this: >- >-$outstring = eregi_replace("badword","goodword",$stringtocheck); >- >-It'll replace it whether it's at the beginning or end of a string, embedded >-in a word, or by itself. Isn't that what you want? >- Not quite. I want to replace words like "ass" and leave works like "assumption" in place. Actually, I did find the answer to the beginning and end of word regex syntax. It is. $outstring = \ eregi_replace("[[:<:]]badword[[:>:]]","goodword",$stringtocheck); This constrains the word and will only act if it is surrounded by non-alpha characters. It acts just like /< and />. I found this answer in the MySQL web page of all things... http://www.mysql.com/doc/R/e/Regexp.html Thanks for your input. John >-Actually, it'd be better and faster to just use str_replace() instead of a >-regular expression... >- >----John Holmes... >- >------ Original Message ----- >-From: "John S. Huggins" <jhuggins@va.net> >-To: <php-general@lists.php.net> >-Sent: Friday, June 14, 2002 11:37 AM >-Subject: [PHP] Beginning /< and end of word /> in eregi_replace >- >- >-> >-> Can it be true that PHP does not implement the beginning and end of word >-> syntax of regular expressions? >-> >-> In builing a bad word filter, I find this... >-> >-> $outstring = eregi_replace("badword$","goodword",$stringtocheck); >-> >-> will find an occurance of the 'badword' at the end of the string and >-> replace it. >-> >-> Similarly, >-> >-> $outstring = eregi_replace("^badword","goodword",$stringtocheck); >-> >-> will find an occurance of the 'badword' at the beginning of the string >-> and replace it. >-> >-> Also, >-> >-> $outstring = eregi_replace("badword","goodword",$stringtocheck); >-> >-> will find all occurances of 'badword' even if they are part of a longer >-> not so bad word like 'badwordage' and replace it. >-> >-> Then, >-> >-> $outstring = eregi_replace(" badword ","goodword",$stringtocheck); >-> >-> will help me isolate just the actual bad word, but not those at the >-> beginning and end of a string or that end in a period or comma. >-> >-> So I could make a rule for each possible placement of badword in a string >-> and then do this for each vulger term I try to filter. Or I could just >-> do... >-> >-> $outstring = >eregi_replace("/<badword/>","goodword",$stringtocheck); >-> >-> Which should find any occurance of 'badword' and nothing more anywhere in >-> the string. It works in grep. It works in bash. It does not seem to >-> work in PHP. >-> >-> Anybody know what I might be doing wrong? >-> >-> ************************************** >-> >-> John Huggins >-> VANet >-> >-> jhuggins@va.net >-> http://www.va.net/ >-> >-> ************************************** >-> >-> >-> -- >-> PHP General Mailing List (http://www.php.net/) >-> To unsubscribe, visit: http://www.php.net/unsub.php >-> >- >- >--- >-PHP General Mailing List (http://www.php.net/) >-To unsubscribe, visit: http://www.php.net/unsub.php >- ************************************** John Huggins VANet jhuggins@va.net http://www.va.net/ **************************************

« previous php.general (#102236) next »