preg_replace 对于专业人士来说很容易
我想找到第一个 select...from 并仅替换它,以下代码替换 sql 查询中的所有 select..from,我只需要第一个 select..from
preg_replace('#select(.*?)from#is', "select count($expr) as counted from", $sql);
i want to find first select ... from and replace that only, following code replace all select..from in sql query, i just need for first select..from
preg_replace('#select(.*?)from#is', "select count($expr) as counted from", $sql);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
preg_replace() 定义替换数量,默认为 -1(意味着无限制)
There is a fourth optional parameter called 'limit' for preg_replace() which defines the number of replacements, and which defaults to -1 (meaning no limit)