note 93338 added to function.str-ireplace

From: Date: Thu, 03 Sep 2009 19:15:48 +0000
Subject: note 93338 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-160202@lists.php.net to get a copy of this message
A more compact form of the highlighting problem with preserved capitalization: <?php // //find and highlight all occurences of string $highlightme in string $subject // - ignore case when searching // - preserve original case when putting <span>...</span> around it //example: // print(highlight("cde","--AbCdEfG--")); //will output: // --Ab<span class=\"highlighted\">CdE</span>fG-- // function highlight($highlightme, $subject) { $result = $subject; preg_match_all("/(".$highlightme.")/i",$subject,$matches); foreach( $matches[0] as $match ) { $result = str_replace($match,"<span class=\"highlighted\">".$match."</span>",$result); } return $result; } ?> ---- Server IP: 212.124.37.9 Probable Submitter: 194.94.115.5 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/93338 Del: integrated -- https://master.php.net/note/delete/93338/integrated Del: useless -- https://master.php.net/note/delete/93338/useless Del: bad code -- https://master.php.net/note/delete/93338/bad+code Del: spam -- https://master.php.net/note/delete/93338/spam Del: non-english -- https://master.php.net/note/delete/93338/non-english Del: in docs -- https://master.php.net/note/delete/93338/in+docs Del: other reasons-- https://master.php.net/note/delete/93338 Reject -- https://master.php.net/note/reject/93338 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160202) next »