note 45113 deleted from function.substr by aidan
| From: | aidan@php.net | Date: | Thu, 26 Aug 2004 22:40:12 +0000 |
| Subject: | note 45113 deleted from function.substr by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75379@lists.php.net to get a copy of this message | ||
Note Submitter: http://www.htmlguiden.tk/
----
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;
}
?>