php - Get a tag href value with specific id -


This is the code I have, and I want to get href value for that ID

 < Code> Function file_get_contents_curl ($ url) {$ ch = curl_init (); Curl_setopt ($ CH, CURLOPT_HEADER, 0); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_FOLLOWLOCATION, 1); $ Data = curl_xac ($ ch); Curl_close ($ ch); $ Return data; } $ Str = 'someLink'; $ Html = file_get_contents_curl ($ str); $ Doc = new DOMDocument (); Libxml_use_internal_errors (true); $ Doc- & gt; Load HTML ('& lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" />'. $ Html); Libxml_clear_errors (); $ Node = $ doc- & gt; GetElementsByTagName ('title'); $ Href value = $ doc- & gt; GetElementById ('Linker');   

Some links HTML examples:

   LINKhere & lt; / A & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

I have to get href value for id = "linker". I try with getElementById (), but it wants to return anything

  $ Node = $ doc- & gt; GetElementsByTagName ('title') - & gt; Items (0) - & gt; Nodeville; $ Href value = $ doc- & gt; GetElementById ('Linker') - & gt; GetAttribute ("href");    

Comments