简体   繁体   中英

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;" causing that script not to work for me.

When I output the variable array from the example, I get variables like [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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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