| Autor | Zpráva | ||
|---|---|---|---|
| Magna Profil * |
#1 · Zasláno: 25. 3. 2015, 16:45:03
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 |
#2 · Zasláno: 25. 3. 2015, 16:49:53
Zápis pole pomocí
[] je podporován myslím od PHP 5.4.
|
||
| Magna Profil * |
#3 · Zasláno: 25. 3. 2015, 16:54:12
Alphard:
Aha pravdu máš, a jak to mám vyřešit? Jednoduchými závorkami? |
||
| juriad Profil |
$streams = array('fce7' => '...'); |
||
| Magna Profil * |
#5 · Zasláno: 25. 3. 2015, 16:59:49
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 |
#6 · Zasláno: 25. 3. 2015, 17:05:09
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 * |
#7 · Zasláno: 25. 3. 2015, 17:09:16
juriad:
PHP info je: allow_url_fopen - on Tak by asi mělo pokud se nemýlím |
||
|
Časová prodleva: 11 let
|
|||
0