note 81539 added to function.str-replace

From: Date: Mon, 03 Mar 2008 14:01:25 +0000
Subject: note 81539 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-136690@lists.php.net to get a copy of this message
/*** * * Highlight specified text. * @param keyword which you want highlighting * @param the bulk of text your highlighting keywords from. * * This example is very basic, and explodes the search words by a space, into an array. * Nonetheless one worded searches are also placed into a single array. */ function QuickHighlight($searchstr,$str){ $search =((strrpos($searchstr," ") ===false)?array($searchstr):explode(" ",$searchstr)); $content =$str; foreach($search as $keyword) $content =str_ireplace($keyword,"<span style='background-color:yellow;'>$keyword</span>", $content); return $content; } Note: str_ireplace is quicker than ereg and there isn't any regular expressions used. for php 4 users, you will need to use str_replace, and play around with some case sencitivity. ---- Server IP: 83.170.119.58 Probable Submitter: 81.137.71.201 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/81539 Del: integrated -- https://master.php.net/note/delete/81539/integrated Del: useless -- https://master.php.net/note/delete/81539/useless Del: bad code -- https://master.php.net/note/delete/81539/bad+code Del: spam -- https://master.php.net/note/delete/81539/spam Del: non-english -- https://master.php.net/note/delete/81539/non-english Del: in docs -- https://master.php.net/note/delete/81539/in+docs Del: other reasons-- https://master.php.net/note/delete/81539 Reject -- https://master.php.net/note/reject/81539 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136690) next »