Home >Backend Development >PHP Tutorial >Short domain name PHP short domain name converted to actual domain name function
Copy code 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 above has introduced the function of converting short domain names into actual domain names in PHP, including the content of short domain names. I hope it will be helpful to friends who are interested in PHP tutorials.