PHP 内爆引用字符串

发布于 2024-11-26 10:33:23 字数 442 浏览 1 评论 0原文

$brand_condition = ' AND ' . mysql_real_escape_string($brand_selection) . ' IN ';

$brand_condition .= $quote10 . '"'. mysql_real_escape_string($brand_value) . '"' .$quote9;

$brand_conditions[] = $brand_condition;

$query .= implode(' AND ', $brand_conditions) . '';

这会产生: ANDManufacturerIN("brand1,brand2")

由于我使用 IN 语句,因此我需要引用这些值。同时,我使用 mysql_real_escape_string 转义潜在的引号。

有谁看到一个简单的方法来解决这个小问题?

$brand_condition = ' AND ' . mysql_real_escape_string($brand_selection) . ' IN ';

$brand_condition .= $quote10 . '"'. mysql_real_escape_string($brand_value) . '"' .$quote9;

$brand_conditions[] = $brand_condition;

$query .= implode(' AND ', $brand_conditions) . '';

This produces: AND manufacturer IN ("brand1,brand2")

Since I'm using the IN statement, I need the values to be quoted. At the same time, I am escaping potential quotes with mysql_real_escape_string.

Does anyone see a simple way to get around this small problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

哆兒滾 2024-12-03 10:33:23
function quote_escape(&$str) {
    $str = '"' . mysql_real_escape_string(chop($str)) . '"';
}

$brands = explode(',', $brand_value);
array_walk($brands, "quote_escape");
$brands = implode(',', $brands);

或者

function quote_escape($str) {
     return '"' . mysql_real_escape_string(chop($str)) . '"';
}
$brands = implode(',', array_map("quote_escape", explode(',', $brand_value)));
function quote_escape(&$str) {
    $str = '"' . mysql_real_escape_string(chop($str)) . '"';
}

$brands = explode(',', $brand_value);
array_walk($brands, "quote_escape");
$brands = implode(',', $brands);

or

function quote_escape($str) {
     return '"' . mysql_real_escape_string(chop($str)) . '"';
}
$brands = implode(',', array_map("quote_escape", explode(',', $brand_value)));
烟柳画桥 2024-12-03 10:33:23

$brand_conditions[] = '"'.$brand_condition.'"'; 怎么样,以便在数组中添加 Brand_condition 之前添加引号。

How about $brand_conditions[] = '"'.$brand_condition.'"'; so your adding quotes right before you add the brand_condition in your array.

清晨说晚安 2024-12-03 10:33:23
$concurrent_names = array("O'reilly", 'Tupac "MC New York" Shakur', 'Nemoden');
$escaped_concurrent_names = array_map('mysql_real_escape_string', $concurrent_names);
$condition = 'WHERE name in ("'.implode('", "', $escaped_concurrent_names).'")';
$concurrent_names = array("O'reilly", 'Tupac "MC New York" Shakur', 'Nemoden');
$escaped_concurrent_names = array_map('mysql_real_escape_string', $concurrent_names);
$condition = 'WHERE name in ("'.implode('", "', $escaped_concurrent_names).'")';
屋顶上的小猫咪 2024-12-03 10:33:23

使用它为内爆字符串添加引号。

$values = implode( " ',' ", array_values($values) );

Use this to add quotes for imploded string.

$values = implode( " ',' ", array_values($values) );

简单 2024-12-03 10:33:23
$brands=array(nokia,samsung,xiomi);

$brands=implode(" ',' ",$brand);

//$brands='nokia','samsung','xiomi';

WHERE column_name IN ($brands)
$brands=array(nokia,samsung,xiomi);

$brands=implode(" ',' ",$brand);

//$brands='nokia','samsung','xiomi';

WHERE column_name IN ($brands)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文