PHP removing html tags from string

后端 未结 6 1839
小鲜肉
小鲜肉 2020-12-02 02:06

I have string:

Vers­lo cent­rai Lie­tu­vos ne­kil­no­ja­mo­jo turto plėt­ros aso­cia­ci­jos kon­kur­se ...

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 02:20

    Since your HTML is not properly formatted you could choose a preg_replace() approach:

    $text = '

    Vers­lo cent­rai Lie­tu­vos ne­kil­no­ja­mo­jo turto plėt­ros aso­cia­ci­jos kon­kur­se ...

    '; $content = preg_replace('/<[^>]*>/', '', $text); var_dump($content); // string(108) "Vers­lo cent­rai Lie­tu­vos ne­kil­no­ja­mo­jo turto plėt­ros aso­cia­ci­jos kon­kur­se ... "

    Codepad Example

    On strip_tags() docs it says: Because strip_tags() does not actually validate the HTML, partial or broken tags can result in the removal of more text/data than expected.

    Also second parameter is for $allowable_tags.

提交回复
热议问题