note 45113 added to function.substr
| From: | http://www dot htmlguiden dot tk/ at osu1 dot php dot net | Date: | Thu, 26 Aug 2004 13:57:47 +0000 |
| Subject: | note 45113 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75334@lists.php.net to get a copy of this message | ||
This fuction finds a needle in a haystack, and returns the needle and a number of signs berfore and
after.
<?php
// string _find(string needle, string haystack, int number of signs before and after);
function _find($needle, $haystack, $num) {
$lenght = strlen($needle);
$startpos = strpos($haystack, $needle);
$dist = $num * 2;
$total = $dist + $lenght;
$str = substr($haystack, $startpos, $total);
$str = str_replace($needle, '<b>'.$needle.'</b>', $str);
return $str;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45113
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45113&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45113&report=yes
Search -- http://master.php.net/manage/user-notes.php