0

Hi i'm using simple_html_dom php library to get contents from other website.

I have below html structure,

<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>

Using this

@$html->find ( 'div[class=nik_block_product_main_info_component_inner] h1',0)->plaintext;

But i'm getting output as DSLR+D7100new

How to get only first plain text i.e, need to fetch only DSLR D7100

0

2 Answers 2

3

You can actually get at that one with:

$html->find('h1 text', 0);
Sign up to request clarification or add additional context in comments.

2 Comments

So simple !! Didn't aware of this. Thank you pguardiario.
@pguardiario Do you have any idea for this
1

We can use a core function to get the result what you want.

$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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.