Re: str_replace on words?

From: Date: Wed, 11 May 2005 21:00:46 +0000
Subject: Re: str_replace on words?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-214978@lists.php.net to get a copy of this message
I whipped this together, it should work ok. You'll want to clean it up, but you get the gist. <?php /* AC Was here */ $str="I'm going to the store to buy some stuff."; $bold=array("store","some","stuff"); function boldWord($str,$bold) { if(isset($str)) {
      foreach($bold as $b) {
        echo "$b should be <b>$b</b>\n";
              $str = eregi_replace($b,"<b>$b</b>",$str);
      }
      $string=$str;
      return $string;
} else {
      $string='The inputed variable $str was empty.';
      return $string;
} } // End function bracket // Example usage if(isset($str)) {
        $string=boldWord($str,$bold);
        echo "Original: $str \n";
        echo "New: $string\n";
} else {
        echo "Variable str not set.";
} ?>

« previous php.general (#214978) next »