&安培; (&符号)符号不在PHP页面中的GET参数值

时间:2013-12-04 16:11:29

标签: javascript php html

我有一个包含以下组件的php页面。单击GET值应显示在文本框

的JavaScript

category= Biscuits & Creams
document.location.href= "page.php?category="+category;

On Load GET参数如下,

page.php?category=Biscuits%20&%20Creams

在php页面中显示值:

<input type="text" Value="<?php echo urlencode($_GET['category']);?>"/>

文本框中的输出将显示为

  

饼干而不是饼干&amp;乳膏

2 个答案:

答案 0 :(得分:3)

PHP引擎使用&分隔查询字符串中的参数。在网址中使用它之前Encode it

答案 1 :(得分:1)

在javascript中添加编码方法,在php中使用urldecode代替urlencode

使用Javascript:

 category= 'Biscuits & Creams';
 document.location.href= "page.php?category="+encodeURIComponent(category);
相关问题