RE: [PHP] Using regex to replace text with bold version - problem with case
| From: | Craig Vincent | Date: | Wed, 12 Jul 2000 20:02:49 +0000 |
| Subject: | RE: [PHP] Using regex to replace text with bold version - problem with case | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6245@lists.php.net to get a copy of this message | ||
> $str = "PHP is great. Isn't php great? I like Php.";
>
> If $criteria equals PHP, Php, php (or even PhP) I want to convert $str to:
>
> <b>PHP</b> is great. Isn't <b>php</b> great? I like
> <b>php</b>.
> 1.
> $str = eregi_replace("$criteria", "<b>$criteria</b>", $txt)
> This converts all case-insensitive occurences of "php" to the
> case used in $criteria.
This *will* work...but your quoting is incorrect
$str = eregi_replace('$criteria', "<b>$criteria</b>", $txt);
You'll notice I replace the needle argument with single instead of double
quotes. This is because using double quotes PHP will first translate the
variable and then do the comparison...so effectively you were asking for
$str = eregi_replace("<b>PHP</b>", "<b>PHP</b>", $txt)
Which first off would not match your current setup and even if it did would
be pointless :)
The single quotes tells PHP not to translate the variable...so it will
actually search for $criteria in the HTML.
Sincerely,
Craig Vincent