Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get just text from ul li?

I am first time on this forum soo hello ;)
I am developing my first professional web page and I have to get text from li element. I am using PHP Simple HTML DOM Parser Manual.

<ul class="siTimeToEnd">
    <li class="left smaller timeInfo">
        <strong>sth</strong>

         foo bar 


    </li>
</ul>

I would like get only 'foo bar' without text in strong attribute. My code:
$date = $page->find("div[id=siWrapper] ul.siTimeToEnd li.timeInfo");

The result it's:

dot (u know dot ;)) <strong>sth</strong> foo bar<br/>

I would get just:

foo bar

I am sorry for my English.

like image 868
Trebuh Avatar asked Jan 22 '26 06:01

Trebuh


1 Answers

The easiest way of handling this is, if the page is well-formed xhtml, you can handle it by using xpath.

For example,

foreach ($page->xpath("//li") as $date) {
        echo $date;
 };

should get you all <li> elements.

If you need a good reference for how to search using xpath expressions, this is a pretty good one: https://developer.mozilla.org/en-US/docs/Web/XPath

like image 63
nomistic Avatar answered Jan 23 '26 18:01

nomistic