I am trying to insert some text after every paragraph in my content.
I explode my content by </p>
It is done using following code:
$Paragraphs = explode( '</p>', $Content);
foreach($Paragraphs as $Paragraph){
// Some code
}
Now my $Content looks like:
<p></p>
<p></p>
<p></p>
<div><p></p></div>
<p></p>
<p></p>
<div><p></p></div>
I want to split if <p>
isn't wrapped inside <div>
or <table>
of anything else.
You can say that the </p>
should have a <p>
after it.
I read Regex can be helpful in achieveing it.
Here's the basic regex I built:
$Pattern = '/<p(|\s+[^>]*)>(.*?)<\/p\s*>/';
if(preg_match_all($Pattern, $Content, $keywords)){
}
This regex currently removes the
itself from the array, it keeps content inside p but not the
itself, and it doesn't check for it being either having a
before it orafter it.