In Variable schreiben geht net

PhoenixDH

Erfahrenes Mitglied
Ich will aus folgendem Quelltext alles in eine Variable schreiben wo vorher echo steht, aber das geht net, wieso ?

Code:
function streaminfo($file,$port) {
  $fp = @fsockopen ($file, $port, &$errno, &$errstr, 5);
  if (!$fp) {
          echo "Could not connect to <b>{$file}:{$port}</b> ({$errno}) - {$errstr}\n";
  } else {
     fputs ($fp, "GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
     while (!feof($fp)) {
      $stream = fgets($fp,1024);
       }
     list(,$stream) = explode("<body>",$stream);
     list($stream) = explode("</body>",$stream);
     list($user, $status, $user_peak, $user_max, ,$bitrate, $song) = explode(",",$stream);
     if($status=="0") {
      echo "<b>{$file}:{$port}</b> is offline!";
     } else {
    echo "<b>{$file}:{$port} on air!</b><br><br>
    <b>user still connected:</b> {$user} of {$user_max}<br>
    <b>user peak:</b> {$user_peak}<br>
    <b>bitrate:</b> {$bitrate} kbits/s<br>
    <b>current song:</b> {$song}<br>";

     }
     fclose($fp);
  }
}

Ich habe es mit
Code:
    $description = "<b>{$file}:{$port} on air!</b><br><br>
    <b>user still connected:</b> {$user} of {$user_max}<br>
    <b>user peak:</b> {$user_peak}<br>
    <b>bitrate:</b> {$bitrate} kbits/s<br>
    <b>current song:</b> {$song}<br>";
versucht ! Aber immer leer !
 
Was meinst du mit "immer leer"? Wenn du die Variable ausserhalb der Funktion weiterverwenden willst, mußt diese auch übermittelt werden.
 
PHP:
function streaminfo($file,$port) {
  $fp = @fsockopen ($file, $port, &$errno, &$errstr, 5);
  if (!$fp) {
          $return = "Could not connect to <b>{$file}:{$port}</b> ({$errno}) - {$errstr}\n";
  } else {
     fputs ($fp, "GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
     while (!feof($fp)) {
      $stream = fgets($fp,1024);
       }
     list(,$stream) = explode("<body>",$stream);
     list($stream) = explode("</body>",$stream);
     list($user, $status, $user_peak, $user_max, ,$bitrate, $song) = explode(",",$stream);
     if($status=="0") {
      $return "<b>{$file}:{$port}</b> is offline!";
     } else {
    $return "<b>{$file}:{$port} on air!</b><br><br>
    <b>user still connected:</b> {$user} of {$user_max}<br>
    <b>user peak:</b> {$user_peak}<br>
    <b>bitrate:</b> {$bitrate} kbits/s<br>
    <b>current song:</b> {$song}<br>";

     }
     fclose($fp);
  }
  return $return;
}
 
Das Funktioniert auch nicht !

Immer noch leer !

Habs jetzt so:
Code:
function streaminfo($file,$port) {
  $fp = @fsockopen ($file, $port, &$errno, &$errstr, 5);
  if (!$fp) {
          $output = "Could not connect to <b>$file:$port</b> ({$errno}) - {$errstr}\n";
  } else {
     fputs ($fp, "GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
     while (!feof($fp)) {
      $stream = fgets($fp,1024);
       }
     list(,$stream) = explode("<body>",$stream);
     list($stream) = explode("</body>",$stream);
     list($user, $status, $user_peak, $user_max, ,$bitrate, $song) = explode(",",$stream);
     if($status=="0") {
     $output = "<b>{$file}:{$port}</b> is offline!";
     } else {
    $output = "<b>$file:$port on air!</b><br><br>
    <b>user still connected:</b> $user of $user_max<br>
    <b>user peak:</b> $user_peak<br>
    <b>bitrate:</b> $bitrate kbits/s<br>
    <b>current song:</b> $song<br>";
     }
     fclose($fp);
  }
     return $output;
} 

streaminfo("***",***);
 
PHP:
$variable = streaminfo("***",***);

Ich empfehle dir doch mal den Besuch auf php.net, um dir die Grundlagen von PHP anzueignen.
 
Zurück