Hi all I am trying to remove all <div> tags but keep its content but couldn't. Working Example: However if: I got the </div> Another problem: I have tried for hours to solve this but couldn't. Need help
preg_replace() won't work well for this because regular expressions do pattern matching and your data doesn't have a pattern; it has a structure, which is a very different beast. You need to parse the document to extract the data you want. You could start with the PHP DOM documentation. Good luck!
Try strip_tags and leave the ones you need. Personally I'd pull the content into an array and phrase from there, but DOM is considered the best way to go by general consensus. ROOFIS
Try this, i am not try before, but it should be a simple PHP script: But, since you had DIV inside the DIV, it may be need recursive to run the preg_replace(). //Output should be : Another CONTENT
@thankyou Try this 100% working example: <?php $mytext = '<div class="group" style="margin-left:10px; margin-bottom:10px;"><div class="group" style="margin-left:10px; margin-bottom:10px;">Another CONTENT</div></div>'; echo strip_tags($mytext); //Output : Another CONTENT ?> PHP: For the example you've given strip-tags is by far the easiest course of action to take without the overhead from complex regex syntax. ROOFIS