【问题标题】:remove <p> from $description variable before storing in database(laravel) [duplicate]在存储到数据库(laravel)之前从 $description 变量中删除 <p> [重复]
【发布时间】:2018-02-21 20:10:27
【问题描述】:

我正在获取输入标记的值,即转换为 Fckeditor 的文本区域:

"<p>bgfbgfbgf</p>\r\n"

我想在删除&lt;p&gt; 标签后将我的值存储在数据库中。

我应该如何从我的值中删除&lt;p&gt;&lt;/p&gt; 标签。 谁能帮我这个。?

【问题讨论】:

    标签: mysql laravel fckeditor


    【解决方案1】:

    如果需要,使用strip_tags 删除标签和str_replace 删除\r\n

    strip_tags(preg_replace('/\s+/', '', $string)))
    

    【讨论】:

      【解决方案2】:
      I think this will solve your problem
      $text = "<p>bgfbgfbgf</p>\r\n";
      $replace = array('<p>','</p>');
      $text =  str_replace($replace,'',$text);
      

      这只会删除 p 个标签。

      【讨论】:

        【解决方案3】:

        要仅删除&lt;p&gt;&lt;/p&gt; 而不删除其他任何内容,请使用preg_replace 和以下regular expression

        $html = "<p>bgfbgfbgf</p>\r\n";
        $string = preg_replace('/<p\b[^>]*>(.*?)<\/p>/is', "", $html);
        

        【讨论】:

          猜你喜欢
          • 2018-03-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-08-24
          • 2017-06-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多