PHP Classes
elePHPant
Icontem

File: 24ur.com_poptv.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Matjaž  >  DynFetcher  >  24ur.com_poptv.php  >  Download  
File: 24ur.com_poptv.php
Role: Example script
Content type: text/plain
Description: Fetches TV station list from 24ur.com
Class: DynFetcher
Extract information from Web pages using SimpleXML
Author: By
Last change:
Date: 7 years ago
Size: 1,669 bytes
 

Contents

Class file image Download
<?php

require 'DynFetcher.class.php';

$URL = 'http://24ur.com/spored/poptv_' . mktime(0, 0, 0, date('m'), date('d'), date('Y')) . '.php';

// XPath expression of items
$itemXPath = '/html/body/table[2]/tr/td/table/tr/td[2]/table/tr/td/div/div';

// Associative array, where key is name of data and value is associative array with the following keys:
// -xpath (required): XPath expression of data, relative from item
// -required: true or false
// -process: PHP code, for additional processing of data
// data is passed as $data variable by reference
// if code returns false data is skipped
$itemData = array(
   
'hour' => array('xpath' => 'span', 'required' => true),
   
'title' => array('xpath' => 'span[2]/span/a', 'process' => '$data = trim($data);'),
   
'title1' => array('xpath' => 'span[2]/span', 'process' => '$data = trim($data);'),
   
'link' => array('xpath' => 'span[2]/span/a/@href', 'process' => '$data = "http://24ur.com" . $data;'),
   
'desc' => array('xpath' => 'span[2]', 'process' => '$data = trim($data);'),
);

// PHP code, for additionl processing of item after all items have been processed
// item is passes as $item variable by reference
// if code returns false item is skipped
$itemProcessFunction = '
    if (!isset($item["title"])) {
        $item["title"] = $item["title1"];
    }
    unset($item["title1"]);
    if (empty($item["desc"])) {
        unset($item["desc"]);
    }

    // return false; // skip item
'
;


header('Content-type: text/plain');

$dyn = new DynFetcher($URL);

var_dump($dyn->find($itemXPath, $itemData, $itemProcessFunction));

?>