php - 为什么 parse_url 返回片段?

标签 php parse-url

我有以下网址:
http://sub.mysite.com/store/?store=Fine+Ting&storeid=3726&test1=value1&test2=value2

使用 print_r(parse_url($url)) 给我这个:

Array ( 
  [scheme] => http 
  [host] => sub.mysite.com 
  [path] => /store/ 
  [query] => store=Fine+Ting& 
  [fragment] => 038;storeid=3726&test1=value1&test2=value2 
) 

根据documentation我应该只在井号 # 之后得到 fragment

为什么 parse_url 返回片段?不应该在 [query] 中吗?

最佳答案

你的 url 有问题,& 符号是在 htmlentities (&) 中编码的。因此 parse_str 认为,片段从那里开始。

尝试使用 html_entity_decode在将 url 传递给 parse_url 之前。

关于php - 为什么 parse_url 返回片段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7987408/

相关文章:

php - Symfony2 中的每主机防火墙

php - 获取我的表单数据以发布到 mysql 数据库

PHP 解析 URL - 当协议(protocol)前缀不存在时域作为路径返回

java - 如何将 txt 文件从精确格式的 url 解析为 TextView ?

php - 使用php在linux中读取图像文件

php - 通过虚拟主机配置设置 Application_ENV 并在 PHP 中读取

javascript - 在 JavaScript 中解析 URL

iphone - 解析 XML iPhone 时清理 URLS(主要针对空格)

iphone - Objective C 中有类似 parse_url 的东西吗?

php - 单个数组元素成为 Zend_Soap_Client 的对象