SnippetVamp

Parce que yen a marre de chercher ses bouts de code partout...



TODO 1 ajax 3 astuce 68 auto_ 2 bash 1 bootstrap 14 conversion 2 crossbrowser 3 css 50 debug 10 dothtaccess 1 effets 1 erreurs 1 evenements 2 fallback 1 fichiers 27 filter 1 fonctions 73 form 1 graphisme 11 html 39 javascript 39 jquery 26 lib 2 mail 1 markdown 2 mobile 2 parser 13 php 91 pluXML 4 python 10 responsive 8 securite 17 social 1 texte 16 vanilla 4

.

Recherche et récup d'infos via allocine: sans API !

Recherche et récup d'infos via allocine: sans API !

<?php
$config=array(
    // Ces regexes pourront être corrigées facilement en cas de changement de la page allocine
    'query_string'=>'http://www.allocine.fr/recherche/1/?q=',
    'base_url'=>'http://www.allocine.fr/',
    'regex_get_links_results'=>'<td[^<]+<a href=["'](/film/fichefilm_gen_cfilm=[^'"]+)',
    'regex_url_image'=>'(http://fr.web.img[^"']+)|(http://images.allocine.fr/[^"']+)',
    'regex_url_image_capture_dim'=>'([a-z])_[0-9]+_[0-9]+',
    'regex_url_image_redim'=>'$1_640_400',
    'regex_get_titre'=>'"label":"([^^]+)","fanCount"', 
    'regex_get_genre'=>'itemprop="genre">([^<]+)', 
    'regex_get_description'=>'itemprop="description">([^<]+)', 
    'regex_get_note'=>'<span class="stars n([^"]+)',
    'regex_get_actors'=>'<span itemprop="name">([^<]+)',
);
function search2array($query){
    global $config;
    //charge la page de recherche d'allocine, retrouve les liens de résultat
    $query=$config['query_string'].str_replace(' ','+',$query);
    $search_page=file_get_contents($query);
    preg_match_all('#'.$config['regex_get_links_results'].'#', $search_page, $results);
    if (count($results[1])>0){return $results[1];}else{return false;}
}

function movielink2array($url){
    global $config;
    //charge la page de la fiche passée en lien, retourne les infos
    $page=file_get_contents($config['base_url'].$url);
    $verif=0;
    $verif+=preg_match('#'.$config['regex_get_titre'].'#', $page, $title);
    $verif+=preg_match('#'.$config['regex_get_genre'].'#', $page, $genre);
    $verif+=preg_match('#'.$config['regex_get_note'].'#', $page, $note);
    $verif+=preg_match('#'.$config['regex_get_description'].'#', $page, $description);
    $verif+=preg_match('#'.$config['regex_url_image'].'#', $page, $image);    
    $verif+=preg_match_all('#'.$config['regex_get_actors'].'#', $page, $actors);

    $image=preg_replace('#'.$config['regex_url_image_capture_dim'].'#',$config['regex_url_image_redim'],$image[0]);
    $result=array();
    $result['movie_actors']=implode(', ',$actors[1]);
    $result['movie_image']=$image;
    $result['movie_allocine_url']=$url;
    if(is_array($title)&&isset($title[1])){$result['movie_title']=$title[1];}else{$result['movie_title']='';}
    if(is_array($note)&&isset($note[1])){$result['movie_stars']=$note[1];}else{$result['movie_stars']=0;}
    if(is_array($genre)&&isset($genre[1])){$result['movie_type']=$genre[1];}else{$result['movie_type']='';}
    if(is_array($description)&&isset($description[1])){$result['movie_description']=$description[1];}else{$result['movie_description']='';}
    
    if (count($result)>0){return $result;}else{return false;}
}

function url_array2list($array=array(),$tpl='<ul><li><img src="movie_image"/></li><li>movie_title</li><li>movie_type</li><li>movie_stars</li><li>movie_actors</li><li>movie_description</li><li><a href="movie_allocine_url">On allocine</a></li></ul>'){
    $list='';
    foreach($array as $url){
        $page=movielink2array($url);

        $list.=str_replace(array_keys($page),array_values($page),$tpl);
    }
    return $list;
}

//ex:
echo url_array2list(search2array('heros'));

?> 

php fonctions parser astuce

http://warriordudimanche.net

<iframe width="100%" height="1316" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=517facafbde0f" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 30/04/2013

Flux RSS de cette page


SnippetVamp 1.83 par Bronco - Page générée en 0.008 s