Ver Mensaje Individual
  #5 (permalink)  
Antiguo 10/09/2014, 15:06
Avatar de Dalam
Dalam
 
Fecha de Ingreso: septiembre-2010
Mensajes: 409
Antigüedad: 13 años, 7 meses
Puntos: 56
Respuesta: Buscar valores repetidos en 2 archivos txt

No lo e chequeado, pero esto deberia de valerte
Código PHP:
Ver original
  1. <?php
  2. function GetProducts($file){
  3.     $regex = "|class=\"producto\"[^>]+>([0-9]*)</[^>]+>|U";
  4.     if(!is_file($file)) return false;
  5.     preg_match_all($regex,file_get_contents($file), $result);
  6.     foreach($result[1] as $key =>$value) $result[$key] = (int) $value;
  7.     return $result;
  8. }
  9.  
  10. function GetListProducts($file){
  11.     if(!is_file($file)) return false;
  12.     $array = array_filter(file($file));
  13.     foreach($array as $key =>$value) $array[$key] = (int) $value;
  14.     return $array;
  15. }
  16.  
  17. function Check($fileReference,$fileHtml){
  18.     $list = GetListProducts($fileReference);
  19.     $html = GetProducts($fileHtml);
  20.     if($list !== false && $html !== false)
  21.         $products = array_intersect($html,$list);
  22.     else
  23.         return false;
  24.     return $products;
  25. }
  26.  
  27.  
  28. //ejemplo de uso con referencia de tus archivos
  29. $products = Check('cache/referencias.txt','cache/html.txt');
  30. //Mostramos el array con los resultados por ejemplo
  31. print_r($products);
__________________
http://www.roglastudios.es

Última edición por Dalam; 10/09/2014 a las 15:15