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.
我第一次参加这个论坛,所以你好;)我正在开发我的第一个专业网页,我必须从li元素中获取文本。我正在使用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");
我想只在强属性中没有文字的'foo bar'。我的代码:$ 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.
我很抱歉我的英语。
2 个解决方案
#1
1
The easiest way of handling this is, if the page is well-formed xhtml, you can handle it by using xpath.
处理这个的最简单方法是,如果页面格式正确xhtml,你可以使用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
如果你需要一个关于如何使用xpath表达式进行搜索的很好的参考,这是一个非常好的参考:https://developer.mozilla.org/en-US/docs/Web/XPath
#2
0
I've solved it ;)
I use strip_tags, substr ;)
我已经解决了;)我使用strip_tags,substr;)
#1
1
The easiest way of handling this is, if the page is well-formed xhtml, you can handle it by using xpath.
处理这个的最简单方法是,如果页面格式正确xhtml,你可以使用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
如果你需要一个关于如何使用xpath表达式进行搜索的很好的参考,这是一个非常好的参考:https://developer.mozilla.org/en-US/docs/Web/XPath
#2
0
I've solved it ;)
I use strip_tags, substr ;)
我已经解决了;)我使用strip_tags,substr;)