回显具有 ' 的变量在他们之中
我有这样的回声,
echo "<a href = 'showdetails.php?name='$name'&type=movie'> </a>";
这正在按预期工作,但例如
$name = Gulliver's Travels;
,我只会在另一页中收到格列佛。
有什么办法可以绕过这个吗?
谢谢,
禅师。
I have this echo,
echo "<a href = 'showdetails.php?name='$name'&type=movie'> </a>";
that is working as intend, but if
$name = Gulliver's Travels;
for example, I will only receive Gulliver in the other page.
Is there any way of circumventing this?
Thanks,
Zenshi.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有许多字符不属于 URL,因此请对它们进行正确编码:
href
值应括在双引号中,而不是单引号中,因为 URL 中允许使用单引号,但不允许使用双引号't。http://php.net/manual/en/function.urlencode.php
如果您将其放入除链接之外的任何其他类型的 HTML 输出中,您需要使用 htmlspecialchars。
There are many characters that don't belong in URLs, so encode them all properly:
The
href
value should be enclosed in double quotes, not single quotes, since single quotes are allowed in URLs but double quotes aren't.http://php.net/manual/en/function.urlencode.php
If you were putting this in any other type of HTML output than a link, you'd want to use htmlspecialchars.
我会选择 urlencode 因为你将它用作 URL 的一部分:
I'd go for urlencode because you are using it as part of an URL: