<?php /** * Funkcja pobierająca dane z podanego adresu, * można zastąpić zwykłą file(), ale użycie CURL'a * jest o wiele bardziej efektywne... * * @author crash : crash (at) os (dot) pl */ function getData( $url, $type = 'array' ) { $data = ''; { } { $curl = curl_init(); curl_setopt( $curl, CURLOPT_URL, $url ); curl_setopt( $curl, CURLOPT_HEADER, false ); curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $curl, CURLOPT_FORBID_REUSE, true ); curl_setopt( $curl, CURLOPT_FRESH_CONNECT, true ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $curl, CURLOPT_TIMEOUT, 25 ); $data = curl_exec( $curl ); curl_close( $curl ); } else { } { } return $data; } /** * Argumenty: * string $parTitle - tytuł filmu, * int $year - rok produkcji, * string $cache - opcjonalna ścieżka do pliku cache * * Zwraca: * array $info * * @author crash : crash (at) os (dot) pl */ function getMovieInfo( $parTitle, $year, $cache = false ) { if( $cache != false ) { { { return $data[ $parTitle ]; } else { foreach( $data as $name => $save ) { { return $save; } } } } } $data = getData( $url1 ); $inPage = false; { foreach( $data as $n => $line ) { { $inPage = true; break; } { { $url2 = $out[ 1 ]; break; } } } { { $info[ 'title' ][ 'original' ] = ( $out[ 2 ] != $year ) ? trim( preg_replace( '/^AKA /', '', html_entity_decode( $out[ 2 ] ) ) ) : $info[ 'title' ][ 'polish' ]; $info[ 'year' ] = $year; } { foreach( $out[ 1 ] as $key => $type ) { $info[ $type ][] = $out[ 2 ][ $key ]; } } { 'Polska' => 'poland', 'Świat' => 'world' ); foreach( $out[ 1 ] as $key => $type ) { } } { $info[ 'time' ] = $out[ 1 ]; } if( preg_match_all( '#(reżyseria|scenariusz|zdjęcia|muzyka)\t+?<a class="n" title="(.+?)- filmografia#', $data, $out ) ) { 'reżyseria' => 'director', 'scenariusz' => 'screenplay', 'zdjęcia' => 'photos', 'muzyka' => 'music' ); foreach( $out[ 1 ] as $key => $type ) { $info[ 'people' ][ $names[ $type ] ] = $out[ 2 ][ $key ]; } } if( preg_match_all( '#<td width="194" align="right"><a class="n" title="(.+?)- filmografia.+?<td width="194" align="left">([^<]+)</td>#s', $data, $out ) ) { foreach( $out[ 1 ] as $key => $who ) { } } } } { if( $cache != false ) { { { $data[ $parTitle ] = $info; } if( preg_match( '#src="(http://gfx.filmweb.pl/f/[^/]+/po.[^.]+.jpg|http://gfx.filmweb.pl/f/[^/]+/[^.]+.jpg)"#', $data, $out ) ) { $info[ 'poster' ] = $out[ 1 ]; } } else { $data[ $parTitle ] = $info; } } } return $info; } ?>
Przykład użycia:
<?php ?>
Wynik:
Kod
Array
(
[title] => Array
(
[polish] => Miasto gniewu
[original] => Crash
)
[year] => 2004
[country] => Array
(
[0] => Niemcy
[1] => USA
)
[genre] => Array
(
[0] => Dramat
[1] => Obyczajowy
)
[premiere] => Array
(
[poland] => 1121983200
[world] => 1094767200
)
[time] => 113
[people] => Array
(
[director] => Paul Haggis
[screenplay] => Paul Haggis
[photos] => James Muro
[music] => Mark Isham
)
[cast] => Array
(
[Sandra Bullock] => Jean
[Don Cheadle] => Graham
[Matt Dillon (I)] => Oficer Ryan
[Jennifer Esposito] => Ria
[William Fichtner] => Flanagan
[Brendan Fraser] => Rick
[Terrence Howard] => Cameron
[Ludacris] => Anthony
[Thandie Newton] => Christine
[Ryan Phillippe] => Oficer Hanson
[Larenz Tate] => Peter
[Tony Danza] => Fred
[Keith David (I)] => Porucznik Dixon
[Shaun Toub] => Farhad
[Loretta Devine] => Shaniqua
)
[poster] => http://gfx.filmweb.pl/f/107996/po.6990411.jpg
)
(
[title] => Array
(
[polish] => Miasto gniewu
[original] => Crash
)
[year] => 2004
[country] => Array
(
[0] => Niemcy
[1] => USA
)
[genre] => Array
(
[0] => Dramat
[1] => Obyczajowy
)
[premiere] => Array
(
[poland] => 1121983200
[world] => 1094767200
)
[time] => 113
[people] => Array
(
[director] => Paul Haggis
[screenplay] => Paul Haggis
[photos] => James Muro
[music] => Mark Isham
)
[cast] => Array
(
[Sandra Bullock] => Jean
[Don Cheadle] => Graham
[Matt Dillon (I)] => Oficer Ryan
[Jennifer Esposito] => Ria
[William Fichtner] => Flanagan
[Brendan Fraser] => Rick
[Terrence Howard] => Cameron
[Ludacris] => Anthony
[Thandie Newton] => Christine
[Ryan Phillippe] => Oficer Hanson
[Larenz Tate] => Peter
[Tony Danza] => Fred
[Keith David (I)] => Porucznik Dixon
[Shaun Toub] => Farhad
[Loretta Devine] => Shaniqua
)
[poster] => http://gfx.filmweb.pl/f/107996/po.6990411.jpg
)
Updated!