note 104827 deleted from function.substr-count by thiago
| From: | thiago@php.net | Date: | Sun, 10 Jul 2011 06:40:22 +0000 |
| Subject: | note 104827 deleted from function.substr-count by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181396@lists.php.net to get a copy of this message | ||
Note Submitter: Aleksey Kuznetsov (utilmind)
----
Here is the function that counts the number of TAG occurrences:
function tag_count($tag, $text, $close = false, $ignore_case = false) {
return preg_match_all('/<'.($close ? '\/' :
'').$tag.'([^>]*?)>/'.($ignore_case ? 'i' : ''),
$text, $v);
}
Examples:
// count of the <b...> tags
print tag_count('b', 'Hello <b style="font-size:14pt">World</b>
<b>Test', false);
> returns 2
// count of the </b...> tags
print tag_count('b', 'Hello <b style="font-size:14pt">World</b>
<b>Test', true);
> returns 1