Sunday 15 July 2012

php - How to get links with mp3 as extension -


I have this code that removes all links from the website. How can I edit it so that it only Removes links that end in MP3? Here are the following codes:

  preg_match_all ("/ \ & lt; a. + Href = (\" | ') (?! Javascript: | #) (. +?) (\ " | '' / I ", $ html, $ match);    

Update:

A good solution must be used together Also, as the @zerkms described in the comment:

  $ doc = new DOMDocument (); $ Doctor & gt; LoadHTML ($ yourHtml); $ Xpath = new DOMXPath ($ doc); // XPath function ends using - MP3 $ link = $ xpath-> To select only those links ending with the query- ('// one [end-with (@ RFF, mp3')] / @ href '); Basic Answer:  

I will use the DOM for this:

  $ doc = new DOMDocument (); $ Doctor & gt; LoadHTML ($ yourHtml); $ Links = array (); Foreign currency ($ doc-> getElementsByTagName ('a') as $ elem) {if ($ elem-> isativity ('href) & amp; amp; and & quot; preg_match (' /.* .. $ $ i /, $ Elem-> getAttribute ('href')) {$ links [] = $ elem-> GetAttribute ('href');}} var_dump ($ link);    

No comments:

Post a Comment