解决url中&times会被转成×的问题

解决url中&times会被转成×的问题


参考原文:的博客《×被转义为X的问题


一、发生错误的情况:

在URL中参数若有&times则会被转成x,例如:

$url = "http://www.test.com/index.php?id=1&timestamp=1584947618&age=10";
echo $url;
输出结果为:http://www.test.com/index.php?id=1×tamp=1584947618&age=10
可以看到参数&timestamp变成了xtamp。

二、解决办法:方法

方法1、既然是&符号和times结合会被转义,那就不写在一起,将参数放在第一位。

$url = "http://www.test.com/index.php?timestamp=1584947618&id=1&age=10";
echo $url;

方法2、把【&】符号转义成html实体,【&】的实体是【&】。

$url = "http://www.test.com/index.php?id=1&timestamp=1584947618&age=10";
echo $url;

方法3、使用htmlspecialchars()函数,把预定义的字符 转成 HTML 实体。

$url = "http://www.test.com/index.php?id=1&timestamp=1584947618&age=10";
echo htmlspecialchars($url);

猜你喜欢

转载自www.cnblogs.com/gyfluck/p/12558079.html