我试图从SQL WHERE查询中删除一些部分。虽然在Regexpal
我的模式没有问题,但当我将表达式放入preg_replace
时,它不起作用。
原始未修改查询WHERE部分的示例:
WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (800,801) ) AND wp_posts.post_type = 'service_photo' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( wp_postmeta.meta_key = 'custom_meta_partner_subscription_level' )
我的代码和模式:
$where = preg_replace("(AND \( wp_term_relationships\.term_taxonomy_id IN \([0123456789,]*\) \))", "", $where);
return $where;
你知道我错了什么吗?
PHP:5.4.19
感谢
答案 0 :(得分:0)
以下是显示PHP中正则表达式用法的示例代码:
$re = "/(AND \\( wp_term_relationships\\.term_taxonomy_id IN \\([0-9,]*\\) \\))/";
$str = "WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (800,801) ) AND wp_posts.post_type = 'service_photo' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( wp_postmeta.meta_key = 'custom_meta_partner_subscription_level' )";
$str = preg_replace($re, "", $str);
请参阅here。
[0123456789,]
可以安全地替换为[0-9,]
。