Possible Duplicate:
How to parse and process HTML with PHP?
$content = "
<p>This is the first paragraph</p>
<p>This is the second paragraph</p>
<p>This is the third paragraph</p>";
Given a string of html content as above, I need to do an insert after the N’th paragraph tag.
How can I parse the content and do an insert of a given string of text, say ‘hello world’ after paragraph 2?
If you are sure about the HTML structure of your string, you can count the seen paragraphs in the callback’s static variable.
Note that this solution is not reentrant, it is only a concept.