简体   繁体   English

PHP脚本编码特殊字符导致错误

[英]php script encoding special characters causes error

I'm attempting to run the script referenced here 我正在尝试运行此处引用的脚本

<?php

$url = 'index.php?option=com_content&view=article&catid=334:golfeq&id=2773:xcelsiors&Itemid=44';

parse_str(parse_url($url, PHP_URL_QUERY), $vars);

echo "Variables:\n";
print_r($vars);

$id = reset(explode(':', $vars['id']));
echo "The id is $id\n";

$id = intval($vars['id']);
echo "Again, the id is $id\n";

Unlike the example shown - which works - on my station, the variable array shows that "&" is encoded to "amp;" 与在我的工作站上显示的有效示例不同,变量数组显示“&”被编码为“ amp;”。 causing that script not to work for me. 导致该脚本不适合我。

When I output the variable array from the example, I get variables like [amp;id] 当我从示例中输出变量数组时,我得到了类似[amp; id]的变量

How can that scriptbe modified with the "&" decoded so it will work on my station? 如何用已解码的“&”修改该脚本,使其在我的工作站上正常工作?

Thanks for your help 谢谢你的帮助

简单的解决方案是

$url = html_entity_decode('index.php?option=com_content&view=article&catid=334:golfeq&id=2773:xcelsiors&Itemid=44');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM