dig555
Постоялец
- Регистрация
 - 22 Июн 2007
 
- Сообщения
 - 365
 
- Реакции
 - 160
 
- Автор темы
 - #1
 
Есть парсер яндекса
	
	
	
		
Напарсенное по запросу $keyword он сохраняет в файл words.txt.
Есть функция транслита, открученная от одного доргена.
	
	
	
		
Помогите, пожалуйста, заставить парсер сохранять итог своей работы в файл с именем "транслит слова из $keyword".txt
	
		
			
		
		
	
				
			
		PHP:
	
	<?php
$keyword="жопа";
$url="http://wordstat.yandex.ru/advq?rpt=ppc&key=&shw=1&tm=&checkboxes=&text=".urlencode($keyword)."®ions_text=%C2%F1%E5®ions=";
$done=false;
while(!$done)
{
   sleep(rand(5,15));
   $ch=curl_init($url);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
   curl_setopt($ch, CURLOPT_TIMEOUT, 15);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_REFERER, "http://yandex.ru");
   $content=curl_exec($ch);
   curl_close($ch);
   $pos=strpos($content, "Что еще");
   if ($pos !== false)
   {
      $content=substr($content,0,$pos);
   }
   $r=preg_match_all('/tm=">([а-я[:print:][:cntrl:]]*?)<\/a><\/td>/i',$content,$matches);
   # print $r;
   $buf="";
   for($i=0; $i<$r; $i++)
   {
      # print $matches[1][$i]."\n";
      $buf.=$matches[1][$i]."\n";
   }
   $fp=fopen("words.txt","a+");
   fwrite($fp,$buf,strlen($buf));
   fflush($fp);
   fclose($fp);
   if (preg_match('/] <a href="(\/advq[[:cntrl:][:print:]]*?)">следующая/',$content,$pocket))
   {
      $url="http://wordstat.yandex.ru".str_replace("&","&",$pocket[1]);
   }
   else
   $done=true;
}
?>
	Есть функция транслита, открученная от одного доргена.
		PHP:
	
	function translit($cyr_str) {
	$razd="-";
	$cyr_str=strtolower($cyr_str);
	$tr =  array("А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
	"Д"=>"d","Е"=>"e","Ж"=>"zh","З"=>"z","И"=>"i",
	"Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
	"О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
	"У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"c","Ч"=>"ch",
	"Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"y","Ь"=>"",
	"Э"=>"e","Ю"=>"u","Я"=>"ya","а"=>"a","б"=>"b",
	"в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
	"з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
	"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
	"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
	"ц"=>"c","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"",
	"ы"=>"y","ь"=>"","э"=>"e","ю"=>"u","я"=>"ya", " " => $razd);
	$text= strtr($cyr_str, $tr);
	$text=preg_replace("/[^a-z0-9_ -]*/", "", $text);
		return $text;
}
	
				
 Предпоследний вопрос. В этом кусочке кода массив $buf записывается в файл.
