URLからhtmlを読み込みページを解析する
任意のURLを指定し、ページ上から、タイトルと概要、写真などを取り出したい場合、
PHP Simple HTML DOM Parserを使用するのがよさげ。
http://simplehtmldom.sourceforge.net/
これを使うと下記のように解析ができる。
これまでは正規表現で書いていたので少しすっきりするかも?
// 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 foreach($html->find('a') as $element) echo $element->href . '<br>';