You are here: eregi_replace? « All PHP « IT news, forums, messages
eregi_replace?

Posted by Pupkin on 11/07/07 23:14

Hi,

I need a case-insensitive replace function to run a string.

I've tried to substitute eregi_replace for str_replace, but it doesn't
seem to work with my array of replaceable terms (it did work on a simple
test, however).

I'm taking a string submitted from a form and flagging words that may
not comply with a set of standards, so that an editor can easily spot
them and decide what to do with them.

Right now it's set-up pretty much like this on my test page:

<?
//simulated string from the form
$ad_text = "THIS STRING IS EMPLOYED TO FLAG REQUIRED LIST OF UNLAWFUL
SINGLE TERMS!";
?>
Unfiltered Text: <?= $ad_text ?>

<?
$bad_words = array('employed', 'law', 'required', 'single');
$flag_bad_words = array('employed**', 'law**', 'required**',
'single**');

//works, but only case-sensitive
//$ad_text = str_replace($bad_words, $flag_bad_words, $ad_text);
//doesn't work at all
$ad_text = eregi_replace($bad_words, $flag_bad_words, $ad_text);

?>
<br />
Filtered Text: <?= $ad_text ?>
</body>

From the example I saw it appeared that the two function were
interchangeble. I guess not.

(I realize that it's probably possible to set-up a loop to go through a
single array of terms and add the "**" where applicable, but I haven't
gotten to that yet. Right now I just want make sure that no matter how
the submitter types the words, if they appear in the string they get
flagged before they come out on the other side.)

Any idea what I'm doing wrong?

Thanks.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация