Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从XPath中删除特定表_Php_Dom_Xpath - Fatal编程技术网

Php 从XPath中删除特定表

Php 从XPath中删除特定表,php,dom,xpath,Php,Dom,Xpath,我有这段代码,并用DOMXPath删除了一个给定的td $html = file_get_contents('WebProxy.html'); $xml = new DOMDocument(); $xml->validateOnParse = true; @$xml->loadHTML($html); $xpath = new DOMXPath($xml); $table =$xpath->query("//*[@id='proxylisttable']")->item

我有这段代码,并用DOMXPath删除了一个给定的td

$html = file_get_contents('WebProxy.html');
$xml = new DOMDocument();
$xml->validateOnParse = true;
@$xml->loadHTML($html);

$xpath = new DOMXPath($xml);
$table =$xpath->query("//*[@id='proxylisttable']")->item(0);

// for printing the whole html table just type: print $xml->saveXML($table); 

$rows = $table->getElementsByTagName("tr");

foreach ($rows as $row) {
  $cells = $row -> getElementsByTagName('td');
  foreach ($cells as $cell) {
        echo $cell->nodeValue. . '<br>';
  }
}


我该怎么做呢,谢谢您的帮助

也许您可以通过排除不需要的单元格来调整xpath查询

例如:

<?php
$html = file_get_contents('WebProxy.html');
$xml = new DOMDocument();
$xml->validateOnParse = true;
@$xml->loadHTML($html);

$xpath = new DOMXPath($xml);
$cells =$xpath->query("//*[@id='proxylisttable']/tr/td[position() != 3 and position() != 6 and position() != 7 and position() != 8]");

foreach ($cells as $cell) {
    echo $cell->nodeValue . "<br>";
}
validateOnParse=true;
@$xml->loadHTML($html);
$xpath=newdomxpath($xml);
$cells=$xpath->query(“/*[@id='proxylistable']/tr/td[position()!=3和position()!=6和position()!=7和position()!=8]”;
foreach($cells作为$cell){
echo$cell->nodeValue。“
”; }
116.226.187.242
    1080
    China
    Socks4
<?php
$html = file_get_contents('WebProxy.html');
$xml = new DOMDocument();
$xml->validateOnParse = true;
@$xml->loadHTML($html);

$xpath = new DOMXPath($xml);
$cells =$xpath->query("//*[@id='proxylisttable']/tr/td[position() != 3 and position() != 6 and position() != 7 and position() != 8]");

foreach ($cells as $cell) {
    echo $cell->nodeValue . "<br>";
}