note 74683 added to function.count-chars
| From: | php-general at lists dot php dot net | Date: | Mon, 23 Apr 2007 14:31:40 +0000 |
| Subject: | note 74683 added to function.count-chars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125797@lists.php.net to get a copy of this message | ||
a function which counts the number of a character in a string:
function countCharInString($str,$chr)
{
foreach(count_chars($str) as $el=>$val)
if(chr($el)==$chr)
return $val;
return 0;
}
echo countCharInString("hello world","l");
this will output:
3
----
Server IP: 69.147.83.197
Probable Submitter: 195.22.236.216
----
Manual Page -- http://www.php.net/manual/en/function.count-chars.php
Edit -- https://master.php.net/note/edit/74683
Del: integrated -- https://master.php.net/note/delete/74683/integrated
Del: useless -- https://master.php.net/note/delete/74683/useless
Del: bad code -- https://master.php.net/note/delete/74683/bad+code
Del: spam -- https://master.php.net/note/delete/74683/spam
Del: non-english -- https://master.php.net/note/delete/74683/non-english
Del: in docs -- https://master.php.net/note/delete/74683/in+docs
Del: other reasons-- https://master.php.net/note/delete/74683
Reject -- https://master.php.net/note/reject/74683
Search -- https://master.php.net/manage/user-notes.php