【发布时间】:2019-09-27 18:16:03
【问题描述】:
我正在为 Laravel 使用 laravel-html-dom-parser 包。
我想获取一个具有 itemprop 属性和值为“price”的跨度的值,所以我编写了这段代码,但它显示了一个错误。
$name = HTMLDomParser::str_get_html('http://www.tgju.org/chart/price_dollar_rl')->find('li > span > itemprop="price"')[0]->plaintext;
我得到的错误是:
preg_match_all():编译失败:偏移量 4 处的字符类范围无效
【问题讨论】:
-
你的 PHP 版本是多少?似乎
sunra/php-simple-html-dom-parser被laravel-html-dom-parseris not compatible with PHP 7.3 使用。还有一个替代方案:github.com/Kub-AT/php-simple-html-dom-parser. -
@UgoT。我正在使用 php 7.3。在您介绍的这个包中,我如何获取具有 itemprop="price" 属性的跨度的值
-
我从来没有使用过这个库,但类似的东西应该会给你你想要的东西:
$name = HTMLDomParser::str_get_html('http://www.tgju.org/chart/price_dollar_rl')->find("li > span[itemprop='price']", 0)->plaintext; -
这只是一个现代包装器,围绕着一段非常过时且写得不好的代码。还有更好的选择,包括 PHP 的内置函数。
-
@miken32 谢谢,如果我不使用这个包怎么能用 PHP 的内置函数做到这一点