This question already has an answer here:
i try to convert the follow string
<p>
string
<b>
bold
<em>italic string</em>
also(bold)
</b>
</p>
to this string
<p>
string
</p> <!--------------------------------------- insert -->
<b>
bold
</b> <!------------------------------------ insert -->
<em>italic string</em>
<b> <!------------------------------------ insert -->
also(bold)
</b>
<p> <!---------------------------------------- insert -->
</p>
i know that is not valid html, but i need this for my project. ... regex its a good way, but i just do not get solved.
the whole strcture will be dynamic,
my thinking was, regex
// open tag close
$regex = '<(.*?)>(.*?)</(.*?)>'
if ($1 != $3) {
$newString = <$1>$2</$1></$3>
}
but don't work!
</div>