- 12 名前:1 [2013/11/11(月) 07:35:43.60 ID:XJY1LijC]
- //HTML取得
$context = stream_context_create(array('http'=>array('method'=>"GET",'header'=>"User-Agent: Mozilla/5.0 (Windows 7; rv:13.0) Gecko/20100101 Firefox/13.0.1"))); $str = file_get_contents("www.yahoo.co.jp/", false, $context); //範囲を抽出 $hani_s = "主なサービス"; $hani_l = "みんなのアンテナ"; $pattern1 = "/(?<=".$hani_s.").*?(?=".$hani_l.")/misu"; if(preg_match($pattern1,$str,$match)) $zentai = nl2br(htmlspecialchars($match[0])); //単語を取得 $tango_s = 'a href="'; $tango_l = '">'; $pattern2 = '/(?<='.$tango_s.').*?(?='.$tango_s.')/misu'; if(preg_match_all($pattern2, $zentai, $match2)) $con = 0; foreach($match2 as $val){ $youso = count($val); while($con < $youso){ echo $val[$con] . "<br />"; $con++; } } HTMLを取得し、正規表現で単語を取り出したいのですが、Notice: Undefined variable: con inとエラーが出てきます $tango_s = 'a href="';をタブルクォート外して$tango_s = 'a href=';にすれば問題なく動くのですが、何が悪いですか?
|

|