Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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/0/xml/15.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
如何获得HTML标记中的文本和PHP中根标记的所有父标记的偏移量?_Php_Html_Offset_Indexof - Fatal编程技术网

如何获得HTML标记中的文本和PHP中根标记的所有父标记的偏移量?

如何获得HTML标记中的文本和PHP中根标记的所有父标记的偏移量?,php,html,offset,indexof,Php,Html,Offset,Indexof,我摘自一篇文章,例如publicationYear,标题和作者如下: $aut = $xpath->query("//table[@cellpadding='6']//b[1]"); $authors = array(); foreach($aut as $node) $authors[] = $node->nodeValue; $title = $doc->getElementsByTagName('h3')->item(1); $publicationYear

我摘自一篇文章,例如publicationYear,标题和作者如下:

$aut = $xpath->query("//table[@cellpadding='6']//b[1]");
$authors = array();
foreach($aut as $node)
    $authors[] = $node->nodeValue;
$title = $doc->getElementsByTagName('h3')->item(1);
$publicationYear = $xpath->query("//p[1]//text()[(following::br)]")->item(0)->nodeValue;
$aux = $xpath->query("//p[2]//text()[(preceding::br)]");
$doi = substr($aux->item($aux->length - 1)->nodeValue, 4);
对于所有字符串(全名、年份、标题),我甚至需要获得前面的所有标记,如:

表格1\u表3\u tbody1\u tr1\u td1\u表5\u tbody1\u tr1\u td2\u p2

标签中的位置如开始:163,结束:190。 我只知道这些信息被分组在特定的标签中,但是如果标签有兄弟姐妹,我甚至需要得到标签的索引,这就是为什么示例中有表3中的forum 1的第三个儿子。 如果有一种方法可以用php或者至少是javascript实现的话

更新 在这篇文章中,我有:

...
<td valign="top"> 
<h3 class="blue-space">D-Lib Magazine</h3>
<p class="blue">November/December 2014<br>
Volume 20, Number 11/12<br><a href="http://www.dlib.org/dlib/november14/brook/../11contents.html" target="_blank">Table of Contents</a>
</p>
...
。。。
D-Lib杂志

2014年11月/12月
第20卷,编号11/12

...
从第一个代码开始的$publicationYear获得这个val 2014。 第一个代码运行良好。 我需要创建其他3个变量,比如$fathers=…td1_p1,
$start=18,$end=22

你的问题有点让人困惑。请给出一个简单的示例输入和相应的示例输出。还要解释什么不适用于您当前的代码,以及您会遇到什么错误(如果有)。编辑后仍然令人困惑。“td1_p1”应该来自哪里?你到底想达到什么目的?您的解析/转换规则是什么?在最后一个html示例中,您可以看到:td1代表第一个,p1代表内部的第一个。在我得到我的文本后,我需要,在这段中,它的坐标(开始和结束的索引);