Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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 DOM而不是preg_替换?_Php_Dom_Replace_Preg Replace - Fatal编程技术网

Php DOM而不是preg_替换?

Php DOM而不是preg_替换?,php,dom,replace,preg-replace,Php,Dom,Replace,Preg Replace,只是尝试用preg_replace删除两个元素,但无法使其一致工作。我想删除具有匹配类的元素。我不习惯PHP,我不知道如何使用语法字符串。我试图自定义示例代码,但它还不起作用 自从有人告诉我用DOM来代替它,我就完全糊涂了 <?php $url = "http://competitive.euw.leagueoflegends.com/de/ladders/euw/current/ranked_team_3x3"; preg_match('#<table class="views

只是尝试用preg_replace删除两个元素,但无法使其一致工作。我想删除具有匹配类的元素。我不习惯PHP,我不知道如何使用语法字符串。我试图自定义示例代码,但它还不起作用

自从有人告诉我用DOM来代替它,我就完全糊涂了

<?php

$url = "http://competitive.euw.leagueoflegends.com/de/ladders/euw/current/ranked_team_3x3";

preg_match('#<table class="views-table cols-6"[^>]+>[\w\W]*?</table>#i', file_get_contents($url), $match);
var_dump($match);
$html = preg_replace('~<td([^>]*)(class\\s*=\\s*["\']views-field views-field-roster-json["\'])([^>]*)>(.*?)</td>#~', '', $html);
$html2 = preg_replace('~<th([^>]*)(class\\s*=\\s*["\']views-field views-field-roster-json["\'])([^>]*)>(.*?)</th>#~', '', $html);
?>

什么工作不一致?DOM是文档对象模型。在这种情况下,使用起来肯定会容易得多,而且破损的可能性也会小得多。您可能还想看看像jquery这样的库,它可以在DOM中查找和操作部分。最后两行行不通。如何禁用数组文本?