PHP-从页面中检索内容 [英] PHP-Retrieve content from page
本文介绍了PHP-从页面中检索内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检索页面的内容并根据我的喜好重新格式化...
I'd like to retrieve a page's content and reformat it to my liking...
例如:
- 转到example.com
- 获取类别为x"的标签内的内容
- 将内容传递给特定变量
- 以某种漂亮的形式吐出内容..array、csv、xml...
不会太难吧?我是 PHP 菜鸟!:)
Not too hard, right? I'm a PHP noob! :)
推荐答案
尝试使用 PHP Simple HTML DOM Parser.
你可以做这样的好事:
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links with class=x
foreach($html->find('a[class=x]') as $element)
echo $element->href . '<br>';
这篇关于PHP-从页面中检索内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文