作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我对以下内容很困惑:
echo("<a href='http://".urlencode("www.test.com/test.php?x=1&y=2")."'>test</a><br>");
echo("<a href='http://"."www.test.com/test.php?x=1&y=2"."'>test</a>");
第一个链接添加了尾部斜线(这给我带来了问题)第二个链接没有。
任何人都可以帮助我理解为什么。显然它似乎与 urlencode 有关,但我无法找出是什么。
谢谢
最佳答案
您不应该使用 urlencode()
来回显 URL,除非它们包含一些非标准字符。
所提供的示例不包含任何异常。
$query = 'hello how are you?';
echo 'http://example.com/?q=' . urlencode($query);
// Ouputs http://example.com/?q=hello+how+are+you%3F
我使用它是因为 $query
变量可能包含空格、问号等。我不能使用问号,因为它表示查询字符串的开头,例如index.php?page=1
。
事实上,该示例最好直接输出而不是echo
。
此外,当我尝试您的示例代码时,我没有得到一个反斜杠,实际上我得到了
<a href='http://www.test.com%2Ftest.php%3Fx%3D1%26y%3D2'>test</a>
关于php - 自动将尾部斜杠添加到 urlencoded url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3830313/
我是一名优秀的程序员,十分优秀!