note 113288 added to function.substr-count
| From: | qeremy | Date: | Fri, 20 Sep 2013 20:45:06 +0000 |
| Subject: | note 113288 added to function.substr-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196332@lists.php.net to get a copy of this message | ||
Unicode example with "case-sensitive" option;
<?php
function substr_count_unicode($str, $substr, $caseSensitive = true, $offset = 0, $length = null) {
if ($offset) {
$str = substr_unicode($str, $offset, $length);
}
$pattern = $caseSensitive
? '~(?:'. preg_quote($substr) .')~u'
: '~(?:'. preg_quote($substr) .')~ui';
preg_match_all($pattern, $str, $matches);
return isset($matches[0]) ? count($matches[0]) : 0;
}
function substr_unicode($str, $start, $length = null) {
return join('', array_slice(
preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY), $start, $length));
}
$s = 'Ãmit yüzüm gözüm...';
print substr_count_unicode($s, 'ü'); // 3
print substr_count_unicode($s, 'ü', false); // 4
print substr_count_unicode($s, 'ü', false, 10); // 1
print substr_count_unicode($s, 'üm'); // 2
print substr_count_unicode($s, 'üm', false); // 3
?>
----
Server IP: 69.147.83.199
Probable Submitter: 5.47.156.0
----
Manual Page -- http://php.net/manual/en/function.substr-count.php
Edit -- https://master.php.net/note/edit/113288
Del: integrated -- https://master.php.net/note/delete/113288/integrated
Del: useless -- https://master.php.net/note/delete/113288/useless
Del: bad code -- https://master.php.net/note/delete/113288/bad+code
Del: spam -- https://master.php.net/note/delete/113288/spam
Del: non-english -- https://master.php.net/note/delete/113288/non-english
Del: in docs -- https://master.php.net/note/delete/113288/in+docs
Del: other reasons-- https://master.php.net/note/delete/113288
Reject -- https://master.php.net/note/reject/113288
Search -- https://master.php.net/manage/user-notes.php