Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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_Xpath - Fatal编程技术网

Php 通过xpath选择多个索引的更好方法

Php 通过xpath选择多个索引的更好方法,php,xpath,Php,Xpath,在一个复杂的表结构中,我尝试在“tr”中选择多个“td” $name = $sxml->xpath(" //table[@cellspacing=0 and @cellpadding=2 and @class='mn2'] /tr[not(contains(@class, 'mn'))]/td[2] | //table[@cellspacing=0 a

在一个复杂的表结构中,我尝试在“tr”中选择多个“td”

$name = $sxml->xpath("
                //table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
                    /tr[not(contains(@class, 'mn'))]/td[2] 
                | 
                //table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
                        /tr[not(contains(@class, 'mn'))]/td[5]
                |
                //table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
                        /tr[not(contains(@class, 'mn'))]/td[7]
                ");

一切都很好,我得到了我想要的,但这似乎有点过头了。如何选择多个“td”,如“td[2,5,7]”,而不是使用联合表达式“|”?

可以借助
完成:

//table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
    /tr[not(contains(@class, 'mn'))]/td[position()=2 or position()=5 or position()=7]