- file_get_contents: documentation ( source)
- mb_convert_encoding: documentation ( source)
- preg_match: documentation ( source)
- preg_match_all: documentation ( source)
- mb_language: documentation ( source)
- preg_replace: documentation ( source)
<?php
$url="http://kakaku.com/camera/camera-lens/itemlist.aspx?pdf_Spec103=13";//取得したいURL
$html=file_get_contents($url);//htmlをゴソっと取得
mb_language("Japanese");//エンコードエラー対策
$html=mb_convert_encoding($html,"utf8","auto");//文字コードをUTF-8に変換
$html=preg_replace("/(\n|\r)/","",$html);//改行コードを全部消す
preg_match_all('@\<div class=\"ranking\"\>(.*?)\<\/div\>@u',$html,$matches);//配列に入れる
foreach($matches[0] as $match){
//商品名
preg_match('@\<a class=\"ckitanker\"\>(.*)\<\/a\>',$match,$product_moto);
$product=$product_moto[1];
print '商品名:'.$product.'<br />';
}
?>