note 85306 added to function.strpos
| From: | mike dot taussick at seznam dot cz | Date: | Mon, 25 Aug 2008 07:26:09 +0000 |
| Subject: | note 85306 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143802@lists.php.net to get a copy of this message | ||
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;
?>
----
Server IP: 147.32.160.17
Probable Submitter: 81.27.199.187
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/85306
Del: integrated -- https://master.php.net/note/delete/85306/integrated
Del: useless -- https://master.php.net/note/delete/85306/useless
Del: bad code -- https://master.php.net/note/delete/85306/bad+code
Del: spam -- https://master.php.net/note/delete/85306/spam
Del: non-english -- https://master.php.net/note/delete/85306/non-english
Del: in docs -- https://master.php.net/note/delete/85306/in+docs
Del: other reasons-- https://master.php.net/note/delete/85306
Reject -- https://master.php.net/note/reject/85306
Search -- https://master.php.net/manage/user-notes.php