note 36612 modified in function.str-replace by aidan

From: Date: Sat, 26 Jun 2004 14:00:20 +0000
Subject: note 36612 modified in function.str-replace by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71769@lists.php.net to get a copy of this message
A simple way of making a case insensitive, multiple words (array) highligt of a string: <?php $needle = array("foo","bar","boo"); // use the | to make preg_replace to use multiple values $needle = join('|',$needle); // use the /i to make case insensitive and \\0 not replace th word but simply to wrap the word. $text = preg_replace("/($needle)/i","<b>\\0</b>",$haystack); ?> Hope you can use it, enjoy Torben --was-- A simple way of making a case insensitive, multiple words (array) highligt of a string: $needle = array("foo","bar","boo"); // use the | to make preg_replace to use multiple values $needle = join('|',$needle); // use the /i to make case insensitive and \\0 not replace th word but simply to wrap the word. $text = preg_replace("/($needle)/i","<b>\\0</b>",$haystack); Hope you can use it, enjoy Torben http://php.net/manual/en/function.str-replace.php

« previous php.notes (#71769) next »