search
Homephp教程php手册PHP将微博短地址还原为实际网址

由于微博中有字数限制,所以如果你发的是网址,会自动将其变为短网址。之前我的几篇文章介绍了如何将网址转为短网址,这里我们反过来,把短网址还原为实际网址。请参照下面的程序,用PHP实现:

<?php
$url = "http://163.fm/1QLJ8U";
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;
}
?>

程序运行结果如下:

http://www.bkjia.com/
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft