Hi there I am requesting you to tell me the simple php script to count special html tag, like <p> in string. I had no idea to try this, since I am the beginner in php.
You can make use of DOMDocument Class for that .
<?php
$html='<p>Hey hello</p><b>Hey this is bold tag</b><p>Another paragraph</p>';
$dom = new DOMDocument;
$dom->loadHTML($html);
echo $dom->getElementsByTagName('p')->length;// "prints" 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With