Php 从具有其他子项的标记中获取文本

Php 从具有其他子项的标记中获取文本,php,dom,html-parsing,Php,Dom,Html Parsing,我在这里有html文件,特别是在这一部分: <p> <a name="Z Distribution (Standard Normal)"> <font color="#000080" size="4"> Z Distribution (Standard Normal). </font> </a> The Z distribution (or standar

我在这里有html文件,特别是在这一部分:

<p>
    <a name="Z Distribution (Standard Normal)">
        <font color="#000080" size="4">
            Z Distribution (Standard Normal). 
        </font>
    </a>
    The Z distribution (or standard normal distribution) function is determined by the following formula:
</p>
它给了我:
Z分布(标准正态)。

我试过写作

foreach ( $html->find('/p/a [size="4"]/font') as $e ) {
但它给了我一页空白


我错过了什么?谢谢。

找到段落,然后从链接中删除文本:

include('simple_html_dom2.php');
$url = 'http://www.statsoft.com//textbook/statistics-glossary/z/?button=0#Z Distribution (Standard Normal)';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);

$html = new simple_html_dom();
$html->load($curl_scraped_page);

foreach ( $html->find('/p/a [size="4"]') as $font ) {
    $link = $font->parent();
    $paragraph = $link->parent();

    $text = str_replace($link->plaintext, '', $paragraph->plaintext);

    echo $text;
}

原始答复:

您的问题与此相关:

您的选择器正在查找
font
标记,其父(
a
标记)是所需文本的同级:

$text = $html->find('/p/a', 0)->next_sibling();

查找
/p
,在该元素内,查找
a
,并从
a
中删除文本。请将该代码放入我的代码中好吗?我想我不知道如何把你的解决方法运用到我的问题中去。。非常感谢。
$text = $html->find('/p/a', 0)->next_sibling();