逃脱&符号

时间:2017-01-11 09:07:13

标签: php ajax escaping htmlspecialchars

我使用Ajax从具有&符号“&”的数据库中检索字符串,如下所示:“双核2.15 GHz Kryo&双核1.44 GHz Kryo”

document.getElementById("cpu'.$i.'").value = $(this).nextAll().eq(2).text();

我在输入字段中显示文本,我可以正确地看到它。 然后,我尝试将其发送到其他页面,使用POST方法,在这里我得到“403错误”...

$cpu=$_POST['cpu'.$p];

我知道这是&符号,因为我的双引号有同样的问题,我解决了这个问题:

htmlentities(stripslashes(utf8_decode($display)))

但我不知道如何逃脱这个&符号...... 我在这里查看其他已发布的问题,但似乎没有任何工作......

请帮助...

解决方案被发布,因为类似的不适合我...

我会给你更多代码:

<?php
for($i=1; $i <= 9; $i++){
${'content' . $i}='<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">

$(function(){
$("#searchid'.$i.'").keyup(function() 
{ 
var searchid'.$i.' = $(this).val();
var dataString = \'search=\'+ searchid'.$i.';
if(searchid'.$i.'!=\'\')
{
    $.ajax({
    type: "POST",
    url: "searchspecs.php",
    data: dataString,
    cache: false,
    success: function(html)
    {
    $("#result'.$i.'").html(html).show();

    $(".name").click(function(){
    document.getElementById("brand'.$i.'").value = $(this).nextAll().eq(7).text();
    document.getElementById("model'.$i.'").value = $(this).nextAll().eq(6).text();
    document.getElementById("id'.$i.'").value = $(this).nextAll().eq(0).text();
    document.getElementById("storage'.$i.'").value = $(this).nextAll().eq(1).text();    
    document.getElementById("cpu'.$i.'").value = $(this).nextAll().eq(2).text();

...

然后:

$cpu=$_POST['cpu'.$p];

还有一个问题......如果我在文本中有“或”,我会收到403禁用错误,例如:“16 GB,32 GB或64 GB”

0 个答案:

没有答案