Php Html Dom解析器获取第一个元素

Php Html Dom解析器获取第一个元素,php,html-parsing,simple-html-dom,Php,Html Parsing,Simple Html Dom,嗨,我正在使用simple\uhtml\udomphp库从其他网站获取内容 我有下面的html结构 <h1 class="nik_product_title" style="color: #000;"> DSLR D7100 <span class="new_big_parent"> <span class="new_big_child"> <span class="new_big_child1">new</spa

嗨,我正在使用
simple\uhtml\udom
php库从其他网站获取内容

我有下面的html结构

<h1 class="nik_product_title" style="color: #000;">
  DSLR D7100
  <span class="new_big_parent">
    <span class="new_big_child">
      <span class="new_big_child1">new</span>
    </span>
  </span>
</h1>
但我得到的输出是DSLR+D7100new


如何只获取第一个纯文本,即只需获取
DSLR D7100

我们可以使用核心函数获得您想要的结果

$html = str_get_html('<h1 class="nik_product_title" style="color: #000;">
DSLR D7100
<span class="new_big_parent">
<span class="new_big_child">
  <span class="new_big_child1">new</span>
</span>
</span>
</h1>');

$last_one =$html->find('h1.nik_product_title',0)->children (0)->plaintext;

$whole =$html->find('h1.nik_product_title',0)->plaintext;

$result = str_replace($last_one,"",$whole);
echo $result;
$html=str\u get\u html('
数码单反D7100
新的
');
$last_one=$html->find('h1.nik_product_title',0)->children(0)->纯文本;
$whole=$html->find('h1.nik_product_title',0)->纯文本;
$result=str_replace($last_one,“,$total);
回声$结果;

我们可以使用核心函数获得您想要的结果

$html = str_get_html('<h1 class="nik_product_title" style="color: #000;">
DSLR D7100
<span class="new_big_parent">
<span class="new_big_child">
  <span class="new_big_child1">new</span>
</span>
</span>
</h1>');

$last_one =$html->find('h1.nik_product_title',0)->children (0)->plaintext;

$whole =$html->find('h1.nik_product_title',0)->plaintext;

$result = str_replace($last_one,"",$whole);
echo $result;
$html=str\u get\u html('
数码单反D7100
新的
');
$last_one=$html->find('h1.nik_product_title',0)->children(0)->纯文本;
$whole=$html->find('h1.nik_product_title',0)->纯文本;
$result=str_replace($last_one,“,$total);
回声$结果;

我们可以使用核心函数获得您想要的结果

$html = str_get_html('<h1 class="nik_product_title" style="color: #000;">
DSLR D7100
<span class="new_big_parent">
<span class="new_big_child">
  <span class="new_big_child1">new</span>
</span>
</span>
</h1>');

$last_one =$html->find('h1.nik_product_title',0)->children (0)->plaintext;

$whole =$html->find('h1.nik_product_title',0)->plaintext;

$result = str_replace($last_one,"",$whole);
echo $result;
$html=str\u get\u html('
数码单反D7100
新的
');
$last_one=$html->find('h1.nik_product_title',0)->children(0)->纯文本;
$whole=$html->find('h1.nik_product_title',0)->纯文本;
$result=str_replace($last_one,“,$total);
回声$结果;

我们可以使用核心函数获得您想要的结果

$html = str_get_html('<h1 class="nik_product_title" style="color: #000;">
DSLR D7100
<span class="new_big_parent">
<span class="new_big_child">
  <span class="new_big_child1">new</span>
</span>
</span>
</h1>');

$last_one =$html->find('h1.nik_product_title',0)->children (0)->plaintext;

$whole =$html->find('h1.nik_product_title',0)->plaintext;

$result = str_replace($last_one,"",$whole);
echo $result;
$html=str\u get\u html('
数码单反D7100
新的
');
$last_one=$html->find('h1.nik_product_title',0)->children(0)->纯文本;
$whole=$html->find('h1.nik_product_title',0)->纯文本;
$result=str_replace($last_one,“,$total);
回声$结果;

您可以通过以下方式获得:

$html->find('h1 text', 0);

实际上,您可以通过以下方式获得:

$html->find('h1 text', 0);

实际上,您可以通过以下方式获得:

$html->find('h1 text', 0);

实际上,您可以通过以下方式获得:

$html->find('h1 text', 0);

谢谢你,古纳。成功了!!谢谢你,古纳。成功了!!谢谢你,古纳。成功了!!谢谢你,古纳。成功了!!太简单了!!我不知道。谢谢你,pguardiario。谢谢@pguardiario,这非常简单answer@pguardiario你对这么简单有什么想法!!我不知道。谢谢你,pguardiario。谢谢@pguardiario,这非常简单answer@pguardiario你对这么简单有什么想法!!我不知道。谢谢你,pguardiario。谢谢@pguardiario,这非常简单answer@pguardiario你对这么简单有什么想法!!我不知道。谢谢你,pguardiario。谢谢@pguardiario,这非常简单answer@pguardiario你有什么想法吗