note 85306 deleted from function.strpos by tularis
| From: | tularis@php.net | Date: | Mon, 25 Aug 2008 11:42:59 +0000 |
| Subject: | note 85306 deleted from function.strpos by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143808@lists.php.net to get a copy of this message | ||
Note Submitter: mike dot taussick at seznam dot cz
Reason: useless
----
Easy function for determining how many times is searched string included in the input one:
<?php
$input = "bu bu bu bu lalala"; // example string
$searched = "bu"; // string we'll try to count in example one
$count = 0;
$buffer = $input;
while ( true ) { // nasty infinite loop x) ..
$next_position = strpos( $buffer, $searched );
if ( $next_position === false ) // ..but followed with quite strong breaking rule
break;
$buffer = substr( $buffer, $next_position + strlen( $searched ) );
$count++;
}
echo $count;
?>