【问题标题】:Use str_replace to remove certain html tags [duplicate]使用 str_replace 删除某些 html 标签 [重复]
【发布时间】:2012-06-28 10:12:12
【问题描述】:

可能重复:
PHP function to strip tags, except a list of whitelisted tags and attributes

我有一个带有一些不需要的 html 标签的数据库,我需要保留一些 html 格式。我尝试使用 str_replace 删除不需要的标签,但它不起作用:

$newdrp = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html>',"",$row_Recordset1['full_description']);

【问题讨论】:

  • 您应该添加有关源文本外观的更多信息。

标签: php str-replace


【解决方案1】:

如果你想删除所有的 html 然后使用这个:

$newdrp = strip_tags($text);

如果你只是想删除一些 html 然后使用这个:

$newdrp = strip_tags($text, '

【讨论】:

    【解决方案2】:

    如果您只想允许某些标签,您可以使用:

    $newdrp = strip_tags($row_Recordset1['full_description'], '<span> <div>');
    

    【讨论】:

      猜你喜欢
      • 2013-08-01
      • 2018-01-03
      • 2016-11-23
      • 2013-04-28
      • 1970-01-01
      • 2023-03-20
      • 2014-12-01
      • 1970-01-01
      • 2020-07-05
      相关资源
      最近更新 更多