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
Post a Comment