I have a div container which I wanted to delete from my coding. The div has an id with a dynamic number.
The div look like this:
< div id="my-message-52617" class="label">
all data inside this div
< /div>
How can I do that using preg_replace
?
I used this:
preg_replace("# < div id=\"my-message- ( . * ? ) \" class=\"label\">([^`]*?) < /div>#", "", $data);
But it seems doesn't work at all.
I need the correct pattern to replace those data.
Try this:
<?php
$data ='aaa<div id="my-message-52617" class="label"> all data inside this div</div><div>This should not be deleted.</div>';
echo preg_replace('#<div id="my-message-(.)*" class="label">[a-zA-Z0-9\s\.]*</div>#','',$data);
It's not working... Thanks anyway bro...
I have a better solution from a friend of mine just now. And it's working fine:
preg_replace('/< div.?id="my-message-[\s\S]? < /div>/i', '', '< div id="my-message-52617" class="label">all data inside this div< /div>');