Home > php教程 > PHP源码 > body text

解析百度搜索结果link?url=

PHP中文网
Release: 2016-05-25 17:09:50
Original
2973 people have browsed it

php代码

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>查询百度link?ulr=真实链接表单</title>
</head>

<body>
<?php
/*
	getrealurl 获取301、302重定向后的URL地址  by enenba.com
	@param str $url 查询
	$return str  定向后的url的真实url
 */
function getrealurl($url){
	$header = get_headers($url,1);
	if (strpos($header[0],&#39;301&#39;) || strpos($header[0],&#39;302&#39;)) {
		if(is_array($header[&#39;Location&#39;])) {
			return $header[&#39;Location&#39;][count($header[&#39;Location&#39;])-1];
		}else{
			return $header[&#39;Location&#39;];
		}
	}else {
		return $url;
	}
}
$input = &#39;<form method="get" action=""><input type="text" name="url" id="url" style="width:800px;" /><input type="submit" value="提交" /></form><body></html>&#39;;

$url = isset($_GET[&#39;url&#39;])?$_GET[&#39;url&#39;]:&#39;&#39;;
if(empty($url)) exit($input);
$urlreal = getrealurl($url);
echo &#39;真实的url为:&#39;.$urlreal;
$urlreal = ltrim($urlreal,&#39;http://&#39;);

$search = &#39;/ebac5573358cc3c0659257bfcf54([0-9a-f]+)/i&#39;;
preg_match($search,$url,$r);
$url_encode = $r[1];  unset($r);

echo &#39;<br/>密文部分为:&#39;.$url_encode.&#39;<br/>&#39;;

$urlreal_arr = str_split($urlreal);
$url_encode_arr = str_split($url_encode,2);

echo &#39;<br />&#39;;
echo $input;
?>
Copy after login
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template