【问题标题】:php - How to remove html tag using regular expression? [duplicate]php - 如何使用正则表达式删除 html 标签? [复制]
【发布时间】:2018-09-05 09:56:42
【问题描述】:

$attributes['st_title'] 的值为<a href="/physical-design-engineers">Physical Design Engineers</a>

我想删除<a href="/physical-design-engineers"></a>。最终预期输出为:$attributes['st_title'] = Physical Design Engineers

我正在尝试如下:

    $pattern[0] = "/<a.[^>]+>/";
    $pattern[1] = '/</a>/';

    $replacement[1] = '';
    $replacement[0] = '';
    $attributes['st_title'] = preg_replace( $pattern, $replacement, $attributes['st_title'] );

但它将$attributes['st_title'] 设置为空。有什么想法吗?

【问题讨论】:

标签: php regex


【解决方案1】:

由于您只需要链接中的文本,因此请使用strip_tags()

echo strip_tags($text); 

https://eval.in/979039

【讨论】:

    【解决方案2】:

    使用phpstrip_tags()

    preg_replace("/<.*?>/", "", $attributes['st_title']);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 2010-10-21
      • 2011-04-16
      • 2017-11-17
      • 2016-09-04
      相关资源
      最近更新 更多