note 104828 added to function.substr-count
| From: | (utilmind) | Date: | Sat, 09 Jul 2011 18:52:15 +0000 |
| Subject: | note 104828 added to function.substr-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181385@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 91.200.180.180
----
Manual Page -- http://www.php.net/manual/en/function.substr-count.php
Edit -- https://master.php.net/note/edit/104828
Del: integrated -- https://master.php.net/note/delete/104828/integrated
Del: useless -- https://master.php.net/note/delete/104828/useless
Del: bad code -- https://master.php.net/note/delete/104828/bad+code
Del: spam -- https://master.php.net/note/delete/104828/spam
Del: non-english -- https://master.php.net/note/delete/104828/non-english
Del: in docs -- https://master.php.net/note/delete/104828/in+docs
Del: other reasons-- https://master.php.net/note/delete/104828
Reject -- https://master.php.net/note/reject/104828
Search -- https://master.php.net/manage/user-notes.php