note 102845 added to function.str-ireplace
| From: | holblin at holblin dot com | Date: | Wed, 09 Mar 2011 21:11:14 +0000 |
| Subject: | note 102845 added to function.str-ireplace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177726@lists.php.net to get a copy of this message | ||
Warning with highlighting ...
I used :
$text = preg_replace('/('.$q.')/i','<span class=highlighting
"">$1</span>' , $text);
Because this line do not allow to highlight uppercase and lowercase correctly (transform uppercase
to lowercase for exemple)
$text = str_ireplace( $q , '<span class=highlighting
"">'.$q.'</span>', $text);
But when $q contain some regex you have some problems ... for exemple :
$q = '(';
So you must use preg_replace to highlight correctly the text and you must create a function for
escape bad regex caracters !
I think that a better function can be found but this works I guess :
function regex_escape( $q )
{
return preg_replace('/([\[\]\(\)\{\}\-\.\*\?\|\^\$])/', '\$1', $q);
}
----
Server IP: 69.147.83.197
Probable Submitter: 87.91.6.54
----
Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php
Edit -- https://master.php.net/note/edit/102845
Del: integrated -- https://master.php.net/note/delete/102845/integrated
Del: useless -- https://master.php.net/note/delete/102845/useless
Del: bad code -- https://master.php.net/note/delete/102845/bad+code
Del: spam -- https://master.php.net/note/delete/102845/spam
Del: non-english -- https://master.php.net/note/delete/102845/non-english
Del: in docs -- https://master.php.net/note/delete/102845/in+docs
Del: other reasons-- https://master.php.net/note/delete/102845
Reject -- https://master.php.net/note/reject/102845
Search -- https://master.php.net/manage/user-notes.php