Php short domain name conversion to the actual domain name function. The copy code is as follows: $ urlsinaurl. cnhbdsU5; echounshorten ($ url); functionunshorten ($ url) {$ urltrim ($ url); $ headersget_headers ($ url); $ location $ url; $ s
The code is as follows:
$ Url = "http://sinaurl.cn/hbdsU5 ";
Echo unshorten ($ url );
Function unshorten ($ url ){
$ Url = trim ($ url );
$ Headers = get_headers ($ url );
$ Location = $ url;
$ Short = false;
Foreach ($ headers as $ head ){
If ($ head = "HTTP/1.1 302 Found") $ short = true;
If ($ short & startwith ($ head, "Location :")){
$ Location = substr ($ head, 10 );
}
}
Return $ location;
}
Function startwith ($ Haystack, $ Needle ){
Return strpos ($ Haystack, $ Needle) === 0;
}
The http://www.bkjia.com/PHPjc/322812.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322812.htmlTechArticle code is as follows: $ url = "http://sinaurl.cn/hbdsU5"; echo unshorten ($ url); function unshorten ($ url) {$ url = trim ($ url ); $ headers = get_headers ($ url); $ location = $ url; $ s...