[ CoaPsyFactor @ 28.05.2011. 17:14 ] @
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]
[ Br@nkoR @ 28.05.2011. 17:43 ] @
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]
[ Miroslav Ćurčić @ 28.05.2011. 18:32 ] @
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.
[ Br@nkoR @ 28.05.2011. 18:39 ] @
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]
[ CoaPsyFactor @ 29.05.2011. 10:07 ] @
@Br@nkoR hvala care!!!!! obozavam te, sa trim sam uspeo :D
[ Br@nkoR @ 29.05.2011. 12:56 ] @
:) 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.