DOMCrawler 截断 text() 中的标签

DOMCrawler truncates tags inside text()

我有一段带有内部自定义标签的文本

$html = '<textarea name="main"><customtag>Hello World!</customtag></textarea>'

$crawler = new Crawler($html);
$text = $crawler->filter('textarea[name="main"]')->text();

print_r($text);

但是 DOMCrawler 在输出中截断了这些标签

Hello World!

为什么?以及如何让 DOMCrawler 留下自定义标签?

为了保留子 html 标签,您需要我们使用 html() 方法,如下所示:

$html = $crawler->filter('textarea[name="main"]')->html();

https://symfony.com/doc/current/components/dom_crawler.html and http://api.symfony.com/4.0/Symfony/Component/DomCrawler/Crawler.html#method_html