i have a string that contains HTML structure :
<p> ... </p>
<p> .... <a> .... </a></p>
<div id="quick_preview">
<p> .... </p>
</div>
<p> ... </p>
and what i want to do is just inject a <description> tag in div with class quick_preview after p tag. something like this :
<p> ... </p>
<p> .... <a> .... </a></p>
<div id="quick_preview">
<description>
<p> .... </p>
</description>
</div>
<p> ... </p>
i use lots of techniques ,like domdocument or string processing, but can’t find the right solution.
Here is a rough example that should help you get started using PHP’s DOM functions. The example will need to be expanded to check for errors and such, but it does work.
Here’s the code: