数据库查询部分的 preg_replace

发布于 2025-01-08 18:03:56 字数 554 浏览 2 评论 0原文

我想这对于专家来说是小菜一碟……我已经抓狂了。 好的,我必须对 WordPress 的“posts_where”查询块执行 preg_replace。这是原文:

$where = " AND (((wp_posts.post_title LIKE '%lorem%') OR (wp_posts.post_content LIKE '%lorem%')*INSERTION*)) AND wp_posts.post_type IN ('post') AND (wp_posts.post_status = 'publish')" 

请注意上面的 INSERTION,我唯一要做的就是插入另一个 OR 条件/子句。 有没有办法用 preg_replace 来做到这一点?不然呢?比如:

$where = preg_replace( "REGEX", $my_INSERTION_stuff, $where );

非常感谢!

编辑

有人愿意解决问题以获得奖品吗?这真的很重要!

I suppose it'll be a piece of cake for an expert ... me already pulling my hair off.
OK, I have to perform preg_replace on a chunk of WordPress' "posts_where" query. Here's the original piece:

$where = " AND (((wp_posts.post_title LIKE '%lorem%') OR (wp_posts.post_content LIKE '%lorem%')*INSERTION*)) AND wp_posts.post_type IN ('post') AND (wp_posts.post_status = 'publish')" 

Please note that INSERTION above, the only thing I gotta do is to insert another OR condition/clause.
Is there a way to do it with preg_replace? Or else? Something like:

$where = preg_replace( "REGEX", $my_INSERTION_stuff, $where );

Thanks a bunch!

EDIT

Anybody willing to resolve the problem for a prize? It's really important!

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

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

发布评论

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

评论(2

风吹雪碎 2025-01-15 18:03:56

您甚至不需要 preg_replace 为此,只需使用 str_replace:

$where = str_replace( "*INSERTION*", $my_INSERTION_stuff, $where );

You do not even need preg_replace for this, just use str_replace:

$where = str_replace( "*INSERTION*", $my_INSERTION_stuff, $where );
葬シ愛 2025-01-15 18:03:56

现在我意识到这可能是多么简单!希望它能帮助某人。

$where = preg_replace("/(AND.*?\))(\)\))/", "$1{$insertion}))", $where, 1);

Right now I have realized how simple it might be! Hopefully it helps someone.

$where = preg_replace("/(AND.*?\))(\)\))/", "$1{$insertion}))", $where, 1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文