PHP code example of b-alidra / xmltv

1. Go to this page and download the library: Download b-alidra/xmltv library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

b-alidra / xmltv example snippets


$xmltv = new XMLTV();

$xmltv
    ->setDate('2016-12-26')
    ->setSourceinfourl('https://b-alidra.com/xmltv')
    ->setSourceinfoname('XMLTV')
    ->setSourcedataurl('https://b-alidra.com/xmltv')
    ->setGeneratorinfoname('XMLTV')
    ->setGeneratorinfourl('https://b-alidra.com/xmltv');

$xmltv->addChannel(function (&$channel) {
    $channel
        // Required attribute
        ->setId('test-channel')
        // Optional children
        ->addDisplayname(['lang' => 'en'], 'The One')
        ->addIcon(['width' => '80', 'height' => 120, 'src' => 'https://b-alidra.com/icon.png'])
        ->addUrl('https://b-alidra.com');;
});

$xmltv->addProgramme([
        // Required attributes
        'channel'          => 'test-channel',
        'start'            => '20161223184000',
        // Optional attributes
        'stop'             => '20161223194000',
        'pdc-start'        => '20161223184000',
        'vps-start'        => '20161223184000',
        'showview'         => '???',
        'videoplus'        => '???',
        'clumpidx'         => '1'
    ], function (&$program) {
        $program
            // Required child
            ->addTitle(['lang' => 'en'], 'Test channel')
            // Optional children
            ->addSubtitle(['lang' => 'en'], 'Test channel second title')
            ->addDesc(['lang' => 'en'], 'Test channel description')
            ->addCredits(function (&$credits) {
                $credits
                    ->addActor('Test actor')
                    ->addAdapter('Test adapter')
                    ->addCommentator('Test commentator')
                    ->addComposer('Test composer')
                    ->addDirector('Test director')
                    ->addEditor('Test editor')
                    ->addGuest('Test guest')
                    ->addPresenter('Test presenter')
                    ->addProducer('Test producer')
                    ->addWriter('Test writer');
            })
            ->addDate('20160615')
            ->addCategory(['lang' => 'en'], 'Horror')
            ->addKeyword(['lang' => 'en'], 'Fantastic')
            ->addLanguage('en')
            ->addOriglanguage('en')
            ->addLength(['units' => 'minutes'], 120)
            ->addIcon(['src' => 'https://b-alidra.com/icon.png'])
            ->addUrl('https://b-alidra.com')
            ->addCountry('GB')
            ->addEpisodenum('0.0.0/1')
            ->addVideo(function (&$video) {
                $video
                    ->addAspect('')
                    ->addColour('')
                    ->addPresent('yes')
                    ->addQuality('');
            })
            ->addAudio(function (&$audio) {
                $audio->addPresent('yes');
            })
            ->addPreviouslyshown([])
            ->addPremiere('')
            ->addLastchance('')
            ->addNew()
            ->addSubtitles(function (&$subtitles) {
                $subtitles->addLanguage('English');
            })
            ->addRating(function (&$rating) {
                $rating
                    ->addValue('1/5')
                    ->addIcon(['src' => 'https://b-alidra.com/icon.png']);
            })
            ->addStarrating(function (&$starrating) {
                $starrating
                    ->addValue('1/5')
                    ->addIcon(['src' => 'https://b-alidra.com/icon.png']);
            })
            ->addReview([
                'type'     => 'text',
                'source'   => 'Web',
                'reviewer' => 'Belkacem Alidra',
                'lang'     => 'en'
            ]);
        });
    });

$output = $xmltv->toXml();

$element->setId($value)

$element->addDisplayname($attributes = [], $value = '', $callback)