简体   繁体   English

在查询中转义双引号

[英]Escape double quotes inside query

I'm scratching my head with this and i can't figure what's wrong 我为此挠头,我不知道怎么了

 $result=mysql_query("SELECT * 
                     FROM `offers` 
                     WHERE 
                     (
                         type='$tran' && 
                         imob='$typeimob' &&
                         (
                           'str_replace("_"," ",$zone)'
                            LIKE CONCAT('%',area,'%')
                         )
                     ) 
                     ORDER BY `price` DESC 
                     LIMIT 0, 50;");
    }

This is inside a php. 这在php内部。 The problem is that I have to escape the double quotes inside str_replace, and i tried str_replace(\\"_\\",\\" \\",$zone) but it doesn't work. 问题是我必须在str_replace中转义双引号,并且尝试了str_replace(\\"_\\",\\" \\",$zone)但是它不起作用。

Any idea? 任何想法?

Thanks 谢谢

You need to concatenate the output of str_replace() into your string. 您需要将str_replace()的输出连接到字符串中。

    $result=mysql_query(
        "SELECT * 
        FROM `offers` 
        WHERE 
        (
        type='$tran' &&
         imob='$typeimob' &&
         (
            '".str_replace("_"," ",$zone)."' 
            LIKE CONCAT('%',area,'%')
            )
        ) 
        ORDER BY `price` DESC LIMIT 0, 50;");

By the way, if you are using an IDE like Eclipse PDT, these things will be apparent to you right away :) 顺便说一句,如果您使用的是像Eclipse PDT这样的IDE,那么这些事情对您而言将立即显而易见:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM