php: Get plain text from html - simplehtmldom or php strip_tags?

后端 未结 5 1519
有刺的猬
有刺的猬 2021-01-15 11:26

I am looking at getting the plain text from html. Which one should I choose, php strip_tags or simplehtmldom plaintext extraction?

One pro for simplehtmldom is suppo

5条回答
  •  迷失自我
    2021-01-15 11:55

    Extracting text from HTML is tricky, so the best option is to use a library like Html2Text. It was built specifically for this purpose.

    https://github.com/mtibben/html2text

    Install using composer:

    composer require html2text/html2text
    

    Basic usage:

    $html = new \Html2Text\Html2Text('Hello, "world"');
    
    echo $html->getText();  // Hello, "WORLD"
    

提交回复
热议问题