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

From: Date: Fri, 14 Jun 2002 16:06:18 +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-102225@lists.php.net to get a copy of this message
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? 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 >

« previous php.general (#102225) next »