mercredi 24 décembre 2014

Improvement of a Pattern

I created this script to take informations "at-the-moment" of this site :


http://ift.tt/1rhjnVW


like :



  • Pictures of name channel

  • Name of channel

  • Pictures channel

  • Times

  • Title

  • Type


My script (Work) :



<?php

$url="http://ift.tt/1rhjnVW";
$code_page = file_get_contents($url);

preg_match_all('/<div class="channelItem">(.*?)<img src="(.*?)" alt="Le programme de (.*?)" width="70" height="30">/is', $code_page, $chaines);
preg_match_all('/<div class="show (.*?) at-the-moment current (.*?)">(.*?)<div class="show-infos">(.*?)<\/div>/is', $code_page, $channels);

$i=0;
foreach ($channels as $channel) {
if($i==3){
for ($j=0; $j < 38; $j++) {
preg_match_all('/<span class="(.*?)"><img src="http:\/\/static.programme-tv.net\/var\/epgs\/169\/80x\/(.*?)" alt="(.*?)" width="80" \/><\/span>/', $channel[$j], $image[$j]);
}
}

if($i==4){
for ($j=0; $j < 38; $j++) {
preg_match_all('/<p class="time">(.*?)<\/p>/', $channel[$j], $time[$j]);
preg_match_all('/<p class="title">(.*?)<\/p>/', $channel[$j], $title[$j]);
preg_match_all('/<p class="type">(.*?)<\/p>/', $channel[$j], $type[$j]);
}
}
$i++;
}

for ($i=0; $i < 38; $i++) {
$test = strpos($chaines[2][$i],' </div>');
if($test != true){
echo 'Chaines images: <img src="'.$chaines[2][$i].'"/><br />';
echo 'Chaines: '.$chaines[3][$i].'<br />';
echo 'image : <img src="http://ift.tt/1B5NT58'.$image[$i][2][0].'" /><br />';
echo 'Temps : '.trim($time[$i][1][0]).'<br />';
echo 'Titre : '.substr($title[$i][1][0], strpos($title[$i][1][0], '>') + 1, strrpos($title[$i][1][0], '<')).'<br />';
echo 'Type : '.$type[$i][1][0].'<br />';
echo '<hr>';
}
}
?>


I would like to improve and find a better Patter. Because i use 4 pattern.


Thank you in advance.


Aucun commentaire:

Enregistrer un commentaire