【问题标题】:How to preg_replace between two characters, erasing comment lines? [duplicate]如何在两个字符之间进行 preg_replace,删除注释行? [复制]
【发布时间】:2018-09-17 23:57:03
【问题描述】:

我正在尝试使用 preg_replace 从数据库中通过 php 删除某些 css 样式中的注释代码。如果使用 srt_replace 或其他一些功能更好,请告诉我该怎么做。

我想删除以下注释的代码:

/*here is some commented code*/
background: #AAA;
/*here is some commented code*/

我上面代码的字符串在$spiderman中:

$ironman = preg_replace("//*(.*?)/*/Uis","",$spiderman);

我怎样才能让 $ironman 变得公正

background: #AAA;

感谢您的帮助。

【问题讨论】:

    标签: php


    【解决方案1】:

    尝试以下带有非贪婪标志的 preg_replace 语句

       echo $ironman = preg_replace("/\/\*(.*)\*\//Uis","",$spiderman);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 2014-04-06
      • 2021-05-26
      • 2011-01-09
      • 2015-08-05
      • 1970-01-01
      相关资源
      最近更新 更多