Autor Zpráva
Magna
Profil *
Tento script:
<?php

function ziskatSouborCache($url) {
  $platnost = 15; // 60 s 
  $soubor = urlencode($url);
 
  if ( // všimni si, že jsem otočil podmínku
      ! file_exists($soubor) ||
      (filemtime($soubor) <= time() - $platnost)
     ) {
    // obsah se musí stáhnout z cizí URL
    $obsah = file_get_contents($url);
    preg_match('/<div id=\"song\-actual\" class=\"stream\-info\"><span>(.*)<\/span><\/div>/', $obsah, $match);
    // uložení obsahu do cache 
    file_put_contents($soubor, $match[1]); 
  } 
  // obsah je určitě v cachi
  return file_get_contents($soubor); 
    
}
 $streams = ['fce7' => 'http://www.radiopetrov.com/stream?type=folk&q=high'];
 
foreach ($streams as $name => $url) {
    $data[$name] = ziskatSouborCache($url);
  
} 
 echo json_encode($data); 
 ?>

Mi na endoře funguje a na hosting-zdarma.cz mi háže chybu : Parse error: syntax error, unexpected '[' in na označeném řádku.

Můžu se zeptat co se mu nelíbí? Děkuji za radu
Alphard
Profil
Zápis pole pomocí [] je podporován myslím od PHP 5.4.
Magna
Profil *
Alphard:
Aha pravdu máš, a jak to mám vyřešit? Jednoduchými závorkami?
juriad
Profil
$streams = array('fce7' => '...');
Magna
Profil *
juriad:
přesně takto to zkouším ale hází to chybu:

Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in

A

Warning: file_get_contents(http://www.radiopetrov.com/stream?type=folk&q=high) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in

na řádku: $obsah = file_get_contents($url);
juriad
Profil
Jo, tvůj hosting nepodporuje stahovaní stránek pomocí funkce file_get_contents (a dalších, které primarně pracují s lokálními soubory).
Magna
Profil *
juriad:
PHP info je: allow_url_fopen - on
Tak by asi mělo pokud se nemýlím

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0