简体   繁体   中英

Regular expression to extract data inside an html code php

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 from 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM