Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

file_get_contents problem...

[es] :: PHP :: file_get_contents problem...

[ Pregleda: 1870 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

CoaPsyFactor
Aleksandar Zivanovic
SoliterInc
Beograd, Srbija

Član broj: 270256
Poruke: 7
*.dynamic.isp.telekom.rs.

Sajt: coa.soliterinc.com/skloni..


Profil

icon file_get_contents problem...28.05.2011. u 17:14 - pre 157 meseci
imam problem sa sledecim kodom, sve uradi kako treba, ali kada treba da uradi file_get_contents($value['URL']) izbaci mi Warning: file_get_contents( http://www.gamespot.com/pc/rpg/thewitcher2/index.html ) [function.file-get-contents]: failed to open stream: Invalid argument in D:\xampp\htdocs\preg\index.php on line 21 i tako za svaki clan iz niza...

Code:

<?
$query = "INSERT INTO items (Item_Category, Item_Image, Item_Title, Item_Description) VALUES ";
$data = array();
for($i = 0; $i<1;$i++){
    $contents = file_get_contents('http://www.gamespot.com/games....asc&official=all&page=' . $i);
    preg_match_all('/<th>\n  <a href="http:\/\/www.gamespot.com\/(.*)\/(.*)\/(.*)\/index.html">(.*)<\/a>\n  <\/th>/', $contents, $matches);
    foreach($matches[4] as $key => $value){
        $contents_new = str_replace('<a href="', '', $matches[0][$key]);
        $contents_new = str_replace('</a>', '', $contents_new);
        $contents_new = str_replace('<th>', '', $contents_new);
        $contents_new = str_replace($value, '', $contents_new);
        $contents_new = str_replace('">', '', $contents_new);
        $contents_new = str_replace('</th>', '', $contents_new);
        $url = str_replace(' ', '', $contents_new);
        $cat = mt_rand(1, 4);        
        $datas = array('URL' =>  $url, 'Game' => $value, 'Category' => $cat);
        $data[] = $datas;
    }
}
foreach($data as $key => $value){
    file_get_contents($value['URL']);
}
?>


[Ovu poruku je menjao flylord dana 30.05.2011. u 09:28 GMT+1]
bolje deset odmah, nego soma ko zna kad.
 
Odgovor na temu

Br@nkoR
http://localhost

Član broj: 2597
Poruke: 1603

Sajt: localhost


+23 Profil

icon Re: file_get_contents problem...28.05.2011. u 17:43 - pre 157 meseci
Vraća li šta funkcija preg_match_all? Odnosno da li se u nizu $matches nalazi ono šta očekuješ? Da li se u $value['URL'] nalazi link? Odradi var_dump tih promenljivih.

Koristi DOM funkcije za parsiranje html-a.


// koristi [code][/code] tag za postavljanje koda

[Ovu poruku je menjao Br@nkoR dana 28.05.2011. u 18:59 GMT+1]
Banned - Not available
 
Odgovor na temu

Miroslav Ćurčić
ex mVeliki
Novi Sad

Član broj: 19034
Poruke: 1118
*.adsl.eunet.rs.



+19 Profil

icon Re: file_get_contents problem...28.05.2011. u 18:32 - pre 157 meseci
Funkcija file_get_contents očekuje paramtear tipa string a ti mu prosleđuješ array. Ako ne grešim.

Za svaki slučaj stavi jedno var_dump($value['URL']); pre poziva te funkcije da vidimo šta prikazuje.
"The quieter you become, the more you are able to hear."
Blog | PowerCMS
 
Odgovor na temu

Br@nkoR
http://localhost

Član broj: 2597
Poruke: 1603

Sajt: localhost


+23 Profil

icon Re: file_get_contents problem...28.05.2011. u 18:39 - pre 157 meseci
Hajde da pokušam ponovo.
Pošto ne mogu da pokrenem kod kod sebe moguće da je es parser "pojeo" koji karakter u regexp, ali pretpostavkom da kod dobro radi sve do drugog poziva file_get_contents funkcije i analizom koda vidim da si zaboravio da ukloniš i nove redove (\n) iz linka (na početku i kraju), pokušaj sa npr.
Code:
file_get_contents(trim($value['URL']));


[Ovu poruku je menjao Br@nkoR dana 28.05.2011. u 19:54 GMT+1]
Banned - Not available
 
Odgovor na temu

CoaPsyFactor
Aleksandar Zivanovic
SoliterInc
Beograd, Srbija

Član broj: 270256
Poruke: 7
*.dynamic.isp.telekom.rs.

Sajt: coa.soliterinc.com/skloni..


Profil

icon Re: file_get_contents problem...29.05.2011. u 10:07 - pre 156 meseci
@Br@nkoR hvala care!!!!! obozavam te, sa trim sam uspeo :D
bolje deset odmah, nego soma ko zna kad.
 
Odgovor na temu

Br@nkoR
http://localhost

Član broj: 2597
Poruke: 1603

Sajt: localhost


+23 Profil

icon Re: file_get_contents problem...29.05.2011. u 12:56 - pre 156 meseci
:) Hvala.
Nema na čemu.
Drago mi je da sam pomogao.
Jedan savet što se tiče RegExp patterna možeš ga napisati kao npr.
Code:
/<th>\s+<a href="(http:\/\/www.gamespot.com\/(.*)\/(.*)\/(.*)\/index.html)">(.*)<\/a>\s+<\/th>/

I onda u $matches[1] dobijaš kompletan sadržaj href atributa a elementa, kako se ne bi zezao sa str_replace funkcijama i uklanjao deo po deo kompletnog match-a.

Pozdrav.
Banned - Not available
 
Odgovor na temu

[es] :: PHP :: file_get_contents problem...

[ Pregleda: 1870 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.