0

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

  • Please see [RegEx match open tags except XHTML self-contained tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). See [this question](http://stackoverflow.com/questions/292926/robust-mature-html-parser-for-php) for information on HTML parsers. – Matthew Flaschen Jul 29 '10 at 21:48

2 Answers2

3

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);
Wrikken
  • 69,272
  • 8
  • 97
  • 136
0

Try this:

preg_match('/<dd><a[^>]*>(.*)<\/a><\/dd>/', $htmlcode, $matches);
$result = $matches[1];
subroutines
  • 1,458
  • 1
  • 12
  • 16