<span class="p_txt1 p_1">
<input type="checkbox" value="value 1">
<b>value 2</b>
</span>
<span class="p_txt1 p_1">
<input type="checkbox" value="value 1">
<b>value 2</b>
</span>
<span class="p_txt1 p_1">
<input type="checkbox" value="value 1">
<b>value 2</b>
</span>
我正在尝试从输入获取值1,从粗体标记获取值2,但它不起作用
$doc = new DOMDocument();
@$doc->loadhtml($contents);
$xpath = new DOMXPath($doc);
$dataString = "";
$fruits = $xpath->query("//span[@class='p_txt1 p_1']");
foreach($fruits as $fruit) {
echo $xmlDate = $fruit->getElementsByTagName( "b" ),"<br>";
}
任何人都可以提供帮助
答案 0 :(得分:1)
试试这个:
$doc = new DOMDocument();
@$doc->loadhtml($contents);
$xpath = new DOMXPath($doc);
$dataString = "";
$fruits = $xpath->query("//span[@class='p_txt1 p_1']");
foreach($fruits as $fruit) {
foreach ($fruit->getElementsByTagName( "b" ) as $xmlBold) {
echo $xmlBold->nodeValue.'<br/>';
}
}