PHP: How to get absolute link of href attribute -



PHP: How to get absolute link of href attribute -

i'm trying fetch favicon image path of site , i'm doing like:

$favicon_img_url = $link->getattribute('href'); echo $favicon_img_url;

but returns relative url (/favicon.ico) , not absolute link (http://www.anysite.com/favicon.ico) want.

edit: more clarity, here's bigger chunk of code:

function file_get_contents_curl($url) { //some code here contents website.... } $html = file_get_contents_curl($target_website); $doc = new domdocument(); @$doc->loadhtml($html); // favicon path $links = $doc->getelementsbytagname('link'); ($i = 0; $i < $links->length; $i++) { $link = $links->item($i); $rel = $link->getattribute('rel'); if($rel == 'shortcut icon') $favicon = $link->getattribute('href'); } echo $favicon;

it returns "/favicon.ico" not "http://www.website.com/favicon.ico"

try add together relative path, domain url $_server['server_name']

edit: give domain without http or https. add together it, can check if https or http: if(isset($_server['https'])){..}else{...}

php

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -