note 104828 deleted from function.substr-count by thiago
| From: | thiago@php.net | Date: | Sun, 10 Jul 2011 06:40:36 +0000 |
| Subject: | note 104828 deleted from function.substr-count by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181397@lists.php.net to get a copy of this message | ||
Note Submitter: Aleksey Kuznetsov (utilmind)
----
Actually the function which I posted in previous is not good enough... In case of search <b>
tags it also can find <br>'s.
Here is the fixed variant:
function tag_count($t, $tag, $close = false, $ignore_case = false) {
return preg_match_all('/<'.($close ? '\/' :
'').$tag.'(>|\/>|\s([^>]*?)>)/'.($ignore_case ? 'i' :
''), $t, $v);
}
Examples:
print tag_count('Hello <b style="font-size: 12pt">World</b>
<b>Test<br/>', 'b', false);
> returns 2
print tag_count('Hello <b style="font-size: 12pt">World</b>
<b>Test<br/>', 'b', false);
> returns 1