Hey, so what I want to do is snag the contents for the first paragraph. The $blog_post contains many paragraphs in the following format:
<p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p>
The problem I am facing is that I am writing a regex to capture everything between the first <p> and the first closing tag </p> . However, it captures the first <p> tag and the tag> last , which leads to me capturing everything.
Here is my current code:
if (preg_match("/[\\s]*<p>[\\s]*(?<firstparagraph>[\\s\\S]+)[\\s]*<\\/p>[\\s\\S]*/",$blog_post,$blog_paragraph)) echo "<p>" . $blog_paragraph["firstparagraph"] . "</p>"; else echo $blog_post;
html php regex html-parsing
Andrew G. Johnson
source share