Показать сообщение отдельно

  #2  
Старый 09.03.2009, 02:51
Pashkela
Динозавр
Регистрация: 10.01.2008
Сообщений: 2,841
Провел на форуме:
9220514

Репутация: 3338


Отправить сообщение для Pashkela с помощью ICQ
По умолчанию

PHP код:
<?php
$res 
fopen('tema3.txt','w'); // Результирующий файл
$ipArray array_map("trim"file("tema1.txt")); // Файл с кейвордами
$file2 fopen('tema2.txt','r'); // Файл с ссылками
while (!feof($file2)) {
  
$buf trim(fgets($file2,4096));
  
preg_match('|>(.*)</a>|',$buf,$out);
  if( 
in_array($out[1],$ipArray)) fwrite ($res,$buf "\r\n");

fclose ($res);
fclose ($file2);
?>
или так:

PHP код:
<?php
$res 
fopen('tema3.txt','w'); // Результирующий файл
$ipArray array_map("trim"file("tema1.txt")); // Файл с кейвордами
$file2 fopen('tema2.txt','r'); // Файл с ссылками
while (!feof($file2)) {
  
$buf trim(fgets($file2,4096));
  for (
$i=0;$i<count($ipArray);$i++){
    if(
strpos($buf,$ipArray[$i])) {fwrite ($res,$buf "\r\n");break;}
  }

fclose ($res);
fclose ($file2);
echo 
'done';
?>
или так (более правильно, не зависит от размеров памяти и размеров обоих файлов):

PHP код:
<?php

function check($str,$file1) {
 while (!
feof($file1)) {
   
$f =  trim(fgets($file1,4096));
   if (
strpos($str,$f)) return true;
 }
 return 
false;  
}



$res fopen('tema3.txt','w'); // Результирующий файл
$file2 fopen('tema2.txt','r'); // Файл с ссылками
$file fopen('tema1.txt','r'); // Файл с кейвордами
while (!feof($file2)) {
  
$buf trim(fgets($file2,4096));
  if(
check($buf,$file)) fwrite ($res,$buf "\r\n");

fclose ($res);
fclose ($file2);
fclose($file);
echo 
'done';
?>
Плюс и мани можешь оставить себе

Последний раз редактировалось Pashkela; 09.03.2009 в 03:51..