PHPDOMnodeValue不是';行不通
我试图用DOM解析一个HTML表,它可以正常工作,但当某些单元格包含HTML时,它就不能正常工作 下面是示例HTML表 电子邮件为空,必须是:PHPDOMnodeValue不是';行不通,php,html,dom,Php,Html,Dom,我试图用DOM解析一个HTML表,它可以正常工作,但当某些单元格包含HTML时,它就不能正常工作 下面是示例HTML表 电子邮件为空,必须是: <img src="generateImage.php?email=myemail@domain.com"/> 而不是 $cells->item(1)->textContent; 但这也不起作用。如何使其返回HTML值?将id作为项目规格提供给您的表 $dom = new DOMDocument(); @$d
<img src="generateImage.php?email=myemail@domain.com"/>
而不是
$cells->item(1)->textContent;
但这也不起作用。如何使其返回HTML值?将id作为项目规格提供给您的表
$dom = new DOMDocument();
@$dom->loadHTML($html);
$x = new DOMXPath($dom);
$table = $x->query("//*[@id='item_specification']/tr");
$rows = $table;
foreach ($rows as $row) {
$atr_name = $row -> getElementsByTagName('td')->item(0)->nodeValue;
$atr_val = $row -> getElementsByTagName('td')->item(1)->nodeValue;
}
echo " {$atr_name} - {$atr_val} <br \>";
$dom=newdomdocument();
@$dom->loadHTML($html);
$x=新的DOMXPath($dom);
$table=$x->query(“//*[@id='item_specification']]/tr”);
$rows=$table;
foreach($行作为$行){
$atr_name=$row->getElementsByTagName('td')->项(0)->节点值;
$atr_val=$row->getElementsByTagName('td')->项(1)->节点值;
}
回声“{$atr_name}-{$atr_val}
”;
工作正常。正如我已经提到的,
不是文本。它是另一个html实体。所以试试这个:
if(strpos($cells->item(0)->textContent, "Razon") !== false) {
$_razonSocial = $cells->item(1)->textContent;
} else if(strpos($cells->item(0)->textContent, "Email") !== false) {
$count = 0;
// here we get all child nodes of td.
// space before img-tag is also a child node, but it has type DOMText
// so we skip it.
foreach ($cells->item(1)->childNodes as $child) {
if (++$count == 2)
$_email = $child->getAttribute('src');
}
// now in $_email you have full src value and can somehow extract email
}
定义“工作不正常”。有错误吗?没有错误,它不会返回任何内容。只是空的。这个变量不是空的吗$_你确定吗?知道吗,希万@Aveendra其为空。
不是文本。它是另一个html实体<代码>$cells->item(1)->item(0)->attr('src')代码>也许
$cells->item(1)->nodeValue;
$cells->item(1)->textContent;
$dom = new DOMDocument();
@$dom->loadHTML($html);
$x = new DOMXPath($dom);
$table = $x->query("//*[@id='item_specification']/tr");
$rows = $table;
foreach ($rows as $row) {
$atr_name = $row -> getElementsByTagName('td')->item(0)->nodeValue;
$atr_val = $row -> getElementsByTagName('td')->item(1)->nodeValue;
}
echo " {$atr_name} - {$atr_val} <br \>";
if(strpos($cells->item(0)->textContent, "Razon") !== false) {
$_razonSocial = $cells->item(1)->textContent;
} else if(strpos($cells->item(0)->textContent, "Email") !== false) {
$count = 0;
// here we get all child nodes of td.
// space before img-tag is also a child node, but it has type DOMText
// so we skip it.
foreach ($cells->item(1)->childNodes as $child) {
if (++$count == 2)
$_email = $child->getAttribute('src');
}
// now in $_email you have full src value and can somehow extract email
}