Share

PHP Simple HTML DOM Parser

Subscribe

Get the text inside a div

You are viewing a single message from this topic. View all messages.

  1. 2009-10-20 01:10:37 UTC

    Hello,

    sorry, I should stop it is very late here.

    you must read in my first answer shows [word1...Word2...The text I want to getWord3...]

    So I give you the right solution (I will send later a complete runtest The code is

    $divchilda=$html->find("div#test")->children();
    

    return the array with 3 elements of the children of #test you can test using

    echo count($divchilda) will send 3

    and

    echo divchilda[2] will send [word3...]
    

    You will never get [The text I want to get], using a basic function. The reason is that the text it a part of a father element and the text functions returns the text content (with or without tags) but can't exclude the innertext of child tags. The can be made by a text treament or by the "label" solution. The solution is given in //sourceforge.net/projects/simplehtmldom/forums/forum/787386/topic/3429553 the text that you want to get is into the main div so it is not plaintext neither outtext neitheir innertext. The best possibility is to use the label tag

    <label for "test"> The text I want to get </label>
    

    This problem don't comes from simple_html_dom but from DOM structure. In your case you could get plaintext and the div text and cut these ones, then you will get the text which are not into the children div elements, but it seams an heavy solution (sometimes there is not another).

    Sorry for the first to quick answer.

    Best regards

< Previous | 1 | Next >

Add a Reply

You can use Markdown syntax in your reply.

Preview

Monitor this

Log in to monitor this topic. Not registered? Create an account to receive email updates when replies are posted to this topic. If you do not log in or register, your reply will be added anonymously.