gpt4 book ai didi

php - 在 href 标记中传递 "&"时,PHP 中的动态 URL 不起作用

转载 作者:可可西里 更新时间:2023-11-01 00:43:17 28 4
gpt4 key购买 nike

我有以下网址

http://localhost:8777/business.php?id=Mobiles and Tablets 

当我在 id 中传递“and”时,它会将我重定向到所需的页面,但是当我传递时

http://localhost:8777/business.php?id=Mobiles & Tablets 

& 即 id 中的 & 符号给出 404 错误。

我的 PHP 代码是这样的:

<a href="business.php?id=<? echo $cat;?>"><? echo $cat;?></a>

最佳答案

你必须使用 urlencode()在您的 PHP 代码中。

<a href="business.php?id=<? echo urlencode($cat) ;?>"><? echo $cat;?></a>

它将生成如下链接:

http://localhost:8777/business.php?id=Mobiles+%26+Tablets

空格会被转换成+&会被转换成%26

关于php - 在 href 标记中传递 "&"时,PHP 中的动态 URL 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27578572/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com