【发布时间】:2020-10-01 01:34:44
【问题描述】:
我正在尝试从 DOM 解析器中获取所有结果,但我只获取了输入字段中的最后一个标签。如果我回显 $link 不是问题。有没有办法像我从 echo 中一样获取所有文本?
<?php
include_once('simple_html_dom.php');
// Create DOM from URL or file
$link = "https://www.sofascore.com/fr/sevilla-real-betis/qgbsIgb";
foreach ($html->find('div.Header__Main-sc-1dyxed1-0.hkVBhG ul li') as $element){
$links = $element->find('a');
foreach ($links as $link) {
echo $link->plaintext.'<br/>';
}
}
?>
<input type="text" name="name" value="<?php echo $link->plaintext?>"><br>
这里是github:https://github.com/inbazhlekov/domm
我希望输入字段中的值为:“Football Espagne LaLiga”,而不仅仅是“LaLiga”。
【问题讨论】:
-
$link 是循环中的最后一个文本。将 $link->plaintext 赋值给像 $inputValue 这样的变量。所以你的代码应该是这样的
$inputValue .= $link->plaintext;。并且不要忘记更改输入值。
标签: php html parsing dom simple-html-dom