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.
2 Answers
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
1 Comment
Alejandro Moreno
there is a very good answer here to read ALL of them: stackoverflow.com/questions/3184284/…