tags:

views:

39

answers:

3

Hi

Let's say that I have this text my db.

<P>word1</P>
<P>word2</P>
<P>word3</P>
<P>word4</P>

How I can detect the number of <p> elements after I get my text from my db?

Thanks

+3  A: 

Use the Simple HTML DOM parser for PHP to parse the contents of the text, select all 'p' elements, then count the size of the resulting array.

Delan Azabani
This is the only way to go. DOM-based [phpQuery](http://code.google.com/p/phpquery/) should make selecting all `<p>` tags dead easy
Pekka
A: 

DOMXpath should put you in the right direction

stillstanding
A: 
Maulik Vora
This will not catch both `<p>` and `<P>`; it will not catch `<p class='classname'>`; it will wrongly catch occurrences of `<p>` in comments.
Pekka