MattR Posted December 16, 2010 Share Posted December 16, 2010 Really cannot see why this doesn't work. $text = "<div id=\"page\"> <div class=\"item\"> Test </div> </div>"; preg_match("#<div id=\"page\"><div class=\"item\">(.*?)</div></div>#m", $text, &$match); var_dump($match); Output: array(0) { } Why?? Quote Link to comment https://forums.phpfreaks.com/topic/221877-preg_match-to-find-div-content/ Share on other sites More sharing options...
mikecampbell Posted December 16, 2010 Share Posted December 16, 2010 You aren't matching the spaces/tabs/newlines that are between your nested div tags. Quote Link to comment https://forums.phpfreaks.com/topic/221877-preg_match-to-find-div-content/#findComment-1148371 Share on other sites More sharing options...
requinix Posted December 16, 2010 Share Posted December 16, 2010 . will only match newlines (\r and \n) if you give the /s regex flag. Quote Link to comment https://forums.phpfreaks.com/topic/221877-preg_match-to-find-div-content/#findComment-1148418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.