Re: Using regex to replace text with bold version - problem with case
| From: | Wico de Leeuw | Date: | Thu, 13 Jul 2000 08:55:48 +0000 |
| Subject: | Re: 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-6397@lists.php.net to get a copy of this message | ||
Hiya
try:
$str = "PHP is great. Isn't php great? I like Php.";
echo preg_replace("'php'i", "<B>\\1</B>", $str)";
Greetz,
Wico
At 09:27 13-7-00 +0100, Matt Williams wrote:
Just one note about this. If you make criteria php which could be your users search and display back the results, all instances of php in the string are converted to lower case due to the eregi_replace. Sorry if you already know about this I just thought it would be worth pointing out. Matt ----- Original Message ----- From: Craig Vincent <webmaster@webdream.com> To: Steven Werby <steven-lists@befriend.com>; <php-general@lists.php.net> Sent: Wednesday, July 12, 2000 9:02 PM Subject: RE: [PHP] Using regex to replace text with bold version - problem with case$str = "PHP is great. Isn't php great? I like Php."; If $criteria equals PHP, Php, php (or even PhP) I want to convert $strto:<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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net