开发者

Regular expression to extract data inside an html code php

开发者 https://www.devze.com 2023-01-09 17:11 出处:网络
how can i extract the data inside this html code <dl class=\"col1\"> <dt>Type:</dt> <dd><a href=\"/browse/102\" title=\"More from this category\">Audio &gt; Audio b

how can i extract the data inside this html code

<dl class="col1">
  <dt>Type:</dt>

  <dd><a href="/browse/102" title="More from this category">Audio &gt; Audio books</a></dd>

i need to extract the

Audio > Audio books fr开发者_运维知识库om the html code using regex in php


Could you not use XPaths?

 $dom = new DOMDocument();
 $dom->loadHTML($yourhtmlstring);
 $x = new DOMXpath($dom);
 foreach($x->query("//dl[@class='col1']/dd/a/text()") as $text) echo htmlentity_decode($text);


Try this:

preg_match('/<dd><a[^>]*>(.*)<\/a><\/dd>/', $htmlcode, $matches);
$result = $matches[1];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号