PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > eregi_replace?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
eregi_replace?

Réponse
 
LinkBack Outils de la discussion
Vieux 07/11/2007, 23h14   #1
Pupkin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut eregi_replace?

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.
  Réponse avec citation
Vieux 07/11/2007, 23h32   #2
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: eregi_replace?


"Pupkin" <spamagnet@dorrk.com> wrote in message
news:MPG.219be6b2d39c0c1f9897e6@news.giganews.com. ..
> Hi,
>
> I need a case-insensitive replace function to run a string.


<snip>

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


very much 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?


you're using eregi_* first of all! see if this s:

<?
$test = 'THIS STRING IS EMPLOYED TO FLAG REQUIRED LIST OF UNLAWFUL SINGLE
TERMS!';
$test = preg_replace('/\b(employed|law|required|single)\b/i', '$1**',
$test);
echo '<pre>' . print_r($test, true) . '</pre>';
?>

notice 'unlawful' is skipped...as would 'singleton'. the whole word is
considered here.



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h40.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08595 seconds with 10 queries