note 82817 added to function.array-map
| From: | BloodElf at osu1 dot php dot net | Date: | Sun, 27 Apr 2008 13:32:13 +0000 |
| Subject: | note 82817 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138844@lists.php.net to get a copy of this message | ||
Here is a simple way to highlight the matched words in the search results:
<?php
function highlight($word) {
static $num = 1;
return '<span class="word' . $num++ . '">' . $word .
'</span>';
}
$text = "ala bala nica turska panica";
$search = "bala turska";
$words = explode(' ', $search);
echo str_replace($words, array_map("highlight", $words), $text);
----
Server IP: 217.75.128.29
Probable Submitter: 87.119.118.109
----
Manual Page -- http://www.php.net/manual/en/function.array-map.php
Edit -- https://master.php.net/note/edit/82817
Del: integrated -- https://master.php.net/note/delete/82817/integrated
Del: useless -- https://master.php.net/note/delete/82817/useless
Del: bad code -- https://master.php.net/note/delete/82817/bad+code
Del: spam -- https://master.php.net/note/delete/82817/spam
Del: non-english -- https://master.php.net/note/delete/82817/non-english
Del: in docs -- https://master.php.net/note/delete/82817/in+docs
Del: other reasons-- https://master.php.net/note/delete/82817
Reject -- https://master.php.net/note/reject/82817
Search -- https://master.php.net/manage/user-notes.php