Home >php教程 >PHP源码 >分析两个 url 查询字符串和 hash 的区别

分析两个 url 查询字符串和 hash 的区别

PHP中文网
PHP中文网Original
2016-05-26 08:19:391184browse

分析两个 url 查询字符串和 hash 的区别

<?php

header("Content-type:text/html; charset=utf-8");

// 分析两个 url 查询字符串和 hash 的区别

$url1 = "http://image.baidu.com/i?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=top&sf=1&fmq=1421654971532_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&itg=0&ie=utf-8&word=%E5%91%A8%E6%9D%B0%E4%BC%A6#z=9&width=0&height=0&pn=";
$url2 = "http://image.baidu.com/i?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=top&sf=1&fmq=1421654971532_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&itg=0&ie=utf-8&word=%E5%91%A8%E6%9D%B0%E4%BC%A6#z=2&width=0&height=0&pn=";

$url1_arr = parse_url($url1);
$url2_arr = parse_url($url2);

parse_str($url1_arr[&#39;query&#39;], $url1_query_arr);
parse_str($url2_arr[&#39;query&#39;], $url2_query_arr);

parse_str($url1_arr[&#39;fragment&#39;], $url1_fragment_arr);
parse_str($url2_arr[&#39;fragment&#39;], $url2_fragment_arr);

$query_diff = array_diff($url1_query_arr, $url2_query_arr);
$fragment_diff = array_diff($url1_fragment_arr, $url2_fragment_arr);

echo "<pre class="brush:php;toolbar:false">";
print_r($query_diff);
print_r($fragment_diff);

 以上就是分析两个 url 查询字符串和 hash 的区别的内容,更多相关内容请关注PHP中文网(www.php.cn)!


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