/ Published in: PHP
This allows you to get contents of any div with ID tag. $matches[0] returns with parent div tag $matches[1] returns with out parent div tag
Expand |
Embed | Plain Text
preg_match('/\<div id\=[\"]{0,1}ad_content[\"]{0,1}\>(.*?)\<\/div\>/s', $content['content_body'], $matches); $content['content_body'] = $matches[1];
Comments
Subscribe to comments
You need to login to post a comment.

This is really awesome and super helpful as I am still blindly making my way around regular expressions. There is a bit of a conundrum for me though, and I'm trying to think of a way around it myself but not getting very far. The issues is this: What if you have a div tag with other divs inside it. Preg_match will stop searching as soon as it hits the first closing div tag. Any thoughts?