regex - PHP basic regular expression -
this question has answer here:
- how parse , process html/xml in php? 27 answers
for example i've kind of content
<div id="t1" class="tt" tag='t2"><div class="t3">tee</div><a href='#'>test</a><span>test</span><div>asdf</div></div> <div id="t1" class="tt" tag='t2"><div class="t3">tee</div><a href='#'>test</a><span>test</span><div>asdf</div></div>
i trying use preg_match content between parent div, here parent divs means <div id="t1"
. use preg_match or there other way data between divs?
a regular expression wrong tool job. want dom parser.
$dom = new domdocument; $dom->loadhtml($html); $t1 = $dom->getelementbyid('t1'); echo $t1->nodevalue;
this return text, if want innerhtml
, try this:
$dom = new domdocument; $dom->loadhtml($html); $t1 = $dom->getelementbyid('t1'); $innerhtml = ''; foreach($t1->childnodes $child){ $innerhtml .= $dom->savehtml($child); } echo $innerhtml;
Comments
Post a Comment