html parsing - How to find content using PHP regular expression -


i want find content inside of div. want specify div’s id; rest automatically adjusted under preg_match. e.g.:

<div id="midbuttonarea" etc...>some text...</div> 

brenton right. anyway, here have:

<?php    function finddivinnerhtml($html, $id){       preg_match("/<div .* id=\"{$id}\" .*>(.*)<\\/div>/i", $html, $matches);       return $matches[1];    } ?> 

sample usage:

<?php    $html = '<div id="other"> xxx </div>  <div id="midbuttonarea" etc...>some text...</div> ';    $innerhtml = finddivinnerhtml($html, 'midbuttonarea');           echo $innerhtml; //outputs "some text..." ?> 

hope helps.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -