【发布时间】:2018-10-13 22:43:56
【问题描述】:
我有几个这样的 HTML 段落(总是相同的结构):
<p>
<!-- Gl. 1-4 -->
\( x(t) = x_0 · t^3 \)
[!equanchor? &id=`555`!]
</p>
我正在通过以下方式成功提取555:
$xpath = new DomXPath($dom);
$paragraphs = $xpath->query('//p');
foreach($paragraphs as $p)
{
$ptext = $p->nodeValue;
if(strpos($ptext, 'equanchor') !== false)
{
// get equation id from anchor
preg_match('/equanchor\?\s\&id=`(.*)\`/', $ptext, $matches);
$equationids[] = (int)$matches[1];
}
}
现在我还需要 HTML 注释 中的文本,即<!-- Gl. 1-4 -->,但我不知道如何为此目的使用 DOM 解析器 (DomXPath)。不幸的是,$p->nodeValue 和 $p->textContent 都包含评论文本。
This answer 没有帮助我。我尝试了一个“子解析器”,但它无法读取$ptext 或$p。
【问题讨论】: