Reputation: 41
i have the following code. and i want to retrieve only the a href titles , that have /movie/ within url.
function get_a_contentmovies(){
$h1count = preg_match_all("/(<a.*>)(\w.*)(<.*>)/ismU",$this->DataFromSite,$patterns);
return $patterns[2];
}
Upvotes: 2
Views: 95
Reputation: 5827
You can use DOMXpath like this:
$dom = new DomDocument();
$dom->loadHTML($string);
$xpath = new DOMXpath($dom);
$elements = $xpath->query("//a[contains(@href, '/movie/')]");
foreach($elements as $el) {
var_dump($el->getAttribute('title'));
}
Upvotes: 1
Reputation: 19899
Using Regex to parse (x)HTML is a bad idea. You should use a DOM parser such as DomDocument. Have a look at this topic.
Upvotes: 0