Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02/11/2011, 15:32
Avatar de ahaugas
ahaugas
 
Fecha de Ingreso: agosto-2011
Ubicación: Madrid
Mensajes: 249
Antigüedad: 12 años, 8 meses
Puntos: 21
Respuesta: problema con foreach

el caso es que esa funcion me imprime una salida en formato texto
Código PHP:
Ver original
  1. echo htmlentities($l)."\n";

y me gustaria sacarlo a $salida para usar en mas de un sitio osea definirle un vallor de salida para despues utilizarlo mas vezes

os dejo el code si quereis

Código PHP:
Ver original
  1. <?php
  2. function curl($link, $cookie) {
  3.     global $Use_fgc;
  4.     if ($Use_fgc || !extension_loaded("curl")) {
  5.         // Using file_get_contents.
  6.         $opt = array(
  7.             'method' => "GET",
  8.             'max_redirects' => 1,
  9.             'header' => "Accept-language: en\r\n" .
  10.             "Cookie: $cookie\r\n" .
  11.             "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2\r\n"
  12.         );
  13.         $context = stream_context_create(array('http' => $opt));
  14.         $page = @file_get_contents($link, false, $context);
  15.         $page = implode("\r\n", $http_response_header) . "\r\n\r\n" . $page;
  16.     } else {
  17.         // Using cURL.
  18.         $ch = curl_init($link);
  19.         curl_setopt($ch, CURLOPT_HEADER, 1);
  20.         curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  21.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  22.         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2");
  23.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  24.         $page = curl_exec($ch);
  25.         $errz = curl_errno($ch);
  26.         $errz2 = curl_error($ch);
  27.         curl_close($ch);
  28.         if ($errz != 0) {
  29.             stop("[cURL:$errz] ".curl_error($ch));
  30.         }
  31.     }
  32.     return($page);
  33. }
  34. function stop($text) {
  35. exit("$text");
  36. }
  37. ?>
  38.  
  39.  
  40. <?php
  41. function GetPLinks($links) {
  42.     global $cookie;
  43.     if (!is_array($links)) stop("???");
  44.     if (empty($cookie['user'])) stop("Cookie not added, please add it.");
  45.  
  46.     $ret = array();
  47.     foreach ($links as $l) {
  48.         $l = "http://www.megaupload.com/?d=".$l;
  49.         $page = curl($l, "user={$cookie['user']};l=en;");
  50.         //if (stristr($page, $mystr))
  51.         if (stristr($page, "\r\nLocation:")){
  52.             if (!preg_match('@Location: (http://www\d+\.megaupload\.com/files/[^\r|\n]+)@i', $page, $rloc)) $rloc[1] = "$l - Unknown redirect found.";
  53.             $ret[] = $rloc[1];
  54.             continue;
  55.         }
  56.         if (!stristr($page, 'flashvars.status = "premium"')) stop("Account isn't premium or cookie is invalid.");
  57.         if (stristr($page, 'password protected')) {
  58.             $ret[] = "$l - Password?";continue;
  59.         }
  60.         if (stristr($page, 'the link you have clicked is not available')) {
  61.             $ret[] = "$l - Link not found";continue;
  62.         }
  63.         if (stristr($page, 'The file you are trying to access is temporarily unavailable')) {
  64.             $ret[] = "$l - Unavailable";continue;
  65.         }
  66.         if (!preg_match('@(http://www\d+\.megaupload\.com/files/[^/]+/[^"|\']+)@i', $page, $rloc)) {
  67.             $ret[] = "$l - Download link not found";continue;
  68.         }
  69.         $ret[] = $rloc[1];
  70.     }
  71.     foreach ($ret as $l) {
  72.         echo htmlentities($l)."\n";
  73.     }
  74. }
  75. ?>
  76.  
  77.  
  78. <?php
  79. if (isset($_REQUEST['video_id'])) {
  80.     // Get IDs
  81.     if ((!empty($_REQUEST['video_id'])) && (preg_match_all("/http:\/\/(?:www\.)?megaupload\.com\/(?:[a-z]{2}\/)?\?d=(?P<lnkID>[0-9a-zA-Z]{8})/i", $_REQUEST['video_id'], $matches))) {
  82.         // Remove duplicated links
  83.         $links = array_values(array_unique($matches['lnkID']));
  84.         // Generate now
  85.         GetPLinks($links);
  86.     } else {
  87.         echo "No links found.";
  88.     }
  89. }
  90.  
  91. ?>

es para imprimirlo en mas de un sitio