How to determine the number of <p> elements stored in my db?

Say I have this text my db.

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

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

thank

+3
source share
3 answers

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

+3
source

DOMXpath should put you in the right direction

0
source
    $text = "<P>word1</P>
<P>word2</P>
<P>word3</P>
<P>word4</P>
";
    $pieces = explode("<p>" , $text);
    echo $pTagCount = count($pieces) - 1;

$ pTagCount will contain the total number of tags

-1
source

Source: https://habr.com/ru/post/1770895/


All Articles