【问题标题】:remove sales offer label from a string从字符串中删除销售报价标签
【发布时间】:2018-10-23 13:12:00
【问题描述】:

我的任务是从描述字段中删除特定句子。 我想使用 preg_replace,但根本不知道如何做到这一点。

输入: 这里我们有一些文字,然后提供 25%,然后是更多的文字

输出应该是: 这里我们有一些文本,然后还有一些文本

所以我需要删除 offer xx% 和任何出现的双倍空格。

有人对此有好的表达方式吗?

提前致谢!

【问题讨论】:

  • 嗯也许我自己找到了一些答案... \boffer\b [0-9]+% ... 测试...

标签: php regex preg-replace


【解决方案1】:

试试offer \d+%。它将匹配文字字符串 offer 后跟 1more 小数后跟 % 符号。

【讨论】:

    【解决方案2】:

    试试这个。

    <?php
       $my_str = "Here we have some text and then offer 25% and then some more text";
       $changed_str = preg_replace("/[0-8]|[%]|(offer)/", " ", $my_str);
    
       print $changed_str ;
    ?>
    

    输出:这里有一些文本,然后是更多文本

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 2013-02-24
      • 2019-06-21
      • 2014-08-07
      • 2010-11-09
      • 1970-01-01
      相关资源
      最近更新 更多