When making a query in MySQL with PHP I get the following result:
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
Several paragraphs with their respective HTML tag<p>
I need to display <div>
the first paragraph in one and the remaining paragraphs <p>
in another .<div>
Something like this:
<div class="sumario">
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
</div>
<div class="cuerpo">
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipiscing elit ut per.</p>
</div>
So far the only thing that has occurred to me is to do the following for the summary:
<?php echo substr(strip_tags($body, '<p>'), 0, 250); ?>
Recommendation:
Well, you can treat it with pure JS, this way you don't mix backend code (PHP) with the use of HTML tags:
querySelectorAll
foreach
we assign the class to each element.primero
and will be red.segundo
and will be greenEXAMPLE
Going by the answer @BetaM gave me, I did the following:
as i have two
<div>
First I print everything in it
<div id="cuerpo">
and then with jQuery I move the first paragraph to<div id="sumario">
:Look for the first closing paragraph tag to get the summary, and from there you get the body:
Note: I am using the HEREDOC structure to create and display strings.