<? $get=$_GET['id']; $lget=$_GET['l_id']; $responce = file_get_contents('http://news.mail.ru/economics/$get/'); preg_match_all('#<<a href="http://www.mail.ru/agent?message&to=([\s\S]*)"><#Ui', $responce, $result); foreach ($result as $value) { echo "Value: $value<br>\n"; $r=$r."\r\n".$value; } echo $r; $fp = fopen("mail.txt", "w"); fwrite($fp, $r); fclose($fp); $get=$get+1; if($lget != $get) { header ("location :http://news.mail.ru/economics/$get/"); }else { echo "Закончили!"; } ?>