Jump to content

Counting HTML Tags: how? -new at REGex.


physaux

Recommended Posts

Hey guys, i read http://weblogtoolscollection.com/regex/regex.php, about an hour ago, so i am really new to regex. My question is, if i had a string, and i wanted to count how many times "<b>" appears, which function would i call for this? I know how to create the "patterns" and such, just not which function to use.

 

ex: preg_something?

 

 

Any pointers greatly appreciated!!

Link to comment
https://forums.phpfreaks.com/topic/178051-counting-html-tags-how-new-at-regex/
Share on other sites

I'd go along with what cags has said. If you want to match using the preg_match_all I'd use '%<b(\b[^>]*)?>%i' as your regex

 

Just a small note; you can remove the optional capture since the word boundary will match even if the following character class (quantized with the asterisk) matches zero times.

 

'~<b\b[^>]*>~i'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.