Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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 如何选择除特定元素之外的所有元素?_Php_Html - Fatal编程技术网

Php 如何选择除特定元素之外的所有元素?

Php 如何选择除特定元素之外的所有元素?,php,html,Php,Html,我有一个这样的结构: <div> <span> <a class="test">one</a> </span> <a>two</a> <a>three</a> </div> 以下是预期结果: two three 正如您在上面的结果中看到的,我想选择所有PHP库。我以前没有使用过这个库,但可能: ->find('a[cl

我有一个这样的结构:

<div>
    <span>
        <a class="test">one</a>
    </span>
    <a>two</a>
    <a>three</a>
</div>
以下是预期结果:

two
three


正如您在上面的结果中看到的,我想选择所有
PHP库。

我以前没有使用过这个库,但可能:

->find('a[class!=test]')-

=>属性过滤器选项卡

我以前没有使用此库,但可能:

->find('a[class!=test]')-
=>属性过滤器选项卡

我的建议(未测试):

$data=$html->find('div',0);
foreach($data->find('a')as$article){
如果($article->getAttribute('class')!='test'){
echo$word.=$article->纯文本。“
”; } }
我的建议(没有测试):

$data=$html->find('div',0);
foreach($data->find('a')as$article){
如果($article->getAttribute('class')!='test'){
echo$word.=$article->纯文本。“
”; } }
->find('a[class!=“test”])-
?仍然不起作用。但是,是的,根据那个链接,你的方法应该是正确的,但我真的不知道为什么它不起作用,无论如何,谢谢你+1对于您的努力
->find('a[class!=“test”])-
?仍然不起作用。但是,是的,根据那个链接,你的方法应该是正确的,但我真的不知道为什么它不起作用,无论如何,谢谢你+谢谢你的努力
->find('a[class!=test]')-
$data = $html->find('div', 0);
foreach($data->find('a') as $article){
  if($article->getAttribute('class') != 'test'){
    echo $word .= $article->plaintext."<br>";
  }
}