数据库查询部分的 preg_replace
我想这对于专家来说是小菜一碟……我已经抓狂了。 好的,我必须对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您甚至不需要 preg_replace 为此,只需使用 str_replace:
You do not even need preg_replace for this, just use str_replace:
现在我意识到这可能是多么简单!希望它能帮助某人。
Right now I have realized how simple it might be! Hopefully it helps someone.