我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

PHP正则表达式的帮助。 的preg_replace

I have four words A,B,C,D. I want to replace all occurrences of A B or A C with A D in given sentence.

I have written this preg_replace("/([A])\s[C|B]/i", "\1 D",$sentence);

But it is not giving correct output. Where I am going wrong?

\ within " are escaping the string special characters, not the regexp special characters. Either you ' as string delimiter or double \ characters:

preg_replace('/([A])\s[C|B]/i', '\1 D', $sentence);

近期文章

  • Laravel-Backpack图像场调试
  • 从私人网站获取postdata
  • PHP用uasort排序数组
  • Symfony 3 FOSRestBundle Twig - 不渲染
  • PHP:如何计算最大值 排列数
  • 嵌套选择数据库sql查询
  • PHP Cron作业引擎
  • 将数据类型结果从MySQL SELECT语句从varchar转换为int
  • 如何在Wordpress中覆盖插件类的功能?
  • 存储段落
  • 有没有办法让一个对象在调用某个函数后调用一个函数?
  • 数组shuffle重复值
  • 如何将以下CURL调用转换为C#
  • 如何在本地计算网页上的社交分享数量
  • Wordpress get_posts()类别参数问题
  • 在php文件中的fullcalendar,javascript和php
  • 通过Laravel返回Javascript文件
  • 在codeigniter中使用jQuery ajax方法获取数据
  • 我怎么能刷新下面的php文件? (没有页面重新加载)
  • 在HTML div中显示文件夹中的所有文本文档?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华