Extracting the first two paragraphs of a content

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Extracting the first two paragraphs of a content

Post by lauthiamkok »

Hi,
I would like to extract the first two paragraphs of a content from a database, the code i got it from somewhere works fine only to extract one (first) paragraph in the content...

Code: Select all

<?php echo substr($row_feeds['pg_content'], 0, strpos($row_feeds['pg_content'], "</p>"));?>
how can i get around to this tricky part...?

Let's say this is my content from the database,

Code: Select all

<p>xxxxx</p>
<p>xxxxx</p>
<p>xxxxx</p>
Thanks,
Lau
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Extracting the first two paragraphs of a content

Post by Christopher »

The first user contributed example on the strings page in the manual might work for you:

http://www.php.net/manual/en/ref.strings.php
(#10850)
Post Reply