简单的 html dom 和文本 [英] simple html dom and text
本文介绍了简单的 html dom 和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设一个简单的html dom对象包括以下内容
suppose that a simple html dom object includes the following
text1
<br />
<br />
<br />
text2
<br />
如何使用简单的 html dom 获取任一文本?
How can i get either of texts using simple html dom?
推荐答案
只需使用纯文本从html中获取文本值即可.
Just use plaintext to get text value from html.
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Accept-language: en\r\n" .
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US;
rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$html1 = new simple_html_dom();
$html1->load_file($url, false, $context);
$appName1 = $html1->find('tagname.classname or id', 0)->plaintext;
类使用 (tagname.classname
) 和 id 使用 (tagname#id
) 获取文本.
For class use (tagname.classname
) and for id use (tagname#id
) to get text.
$context 用于设置浏览器支持的标题,如果任何网站获得移动版本,那么您可以添加标题以获取浏览器支持内容.
$context is for set header for browser support if any website get mobile version so u can add header to get browser support content.
这篇关于简单的 html dom 和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文