Home > Net >  html epg to xml via php
html epg to xml via php

Time:10-25

Please help

I have been finding a code for this but failed

source: https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/23102021.json This is a epg html site

Could you suggest a way to convert this link contents to XML?

btw the link is based on the day https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/ddMMyyyy.json

maybe this will help

site {url=singteltv.com.sg|timezone=Asia/Singapore|maxdays=7|cultureinfo=en-GB|charset=UTF-8|titlematchfactor=90|keepindexpage}
site {ratingsystem=GB|episodesystem=onscreen}
url_index{url|https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/|urldate|.json}
url_index.headers {customheader=Accept-Encoding=gzip,deflate}
urldate.format {datestring|ddMMyyyy}
index_variable_element.modify {set|'config_site_id'}
index_showsplit.scrub {regex||\{"channelid":"'index_variable_element'",".*?"startDateTime":".*?\}||}
index_showsplit.modify {cleanup(style=jsondecode)}
index_start.scrub {single|"startDateTime":"||"|"}
index_title.scrub {regex||"title":"(.*?)",||}
index_description.scrub{regex||"program":\{"description":"(.*?)","||}
**  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _
**      #####  CHANNEL FILE CREATION (only to create the xxx-channel.xml file)
**
** @auto_xml_channel_start
*url_index{url|https://www.singtel.com/personal/products-services/tv/tv-programme-guide}
*index_site_id.scrub {regex()||\{"title":".*?","description".*?"epgChannelId":"(\d )"\}||}
*index_site_channel.scrub {regex()||\{"title":"([^"]*)","description".*?"epgChannelId":"\d "\}||}
** @auto_xml_channel_end
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Preferred output:
<tv generator-info-name="WebGrab Plus/w MDB & REX Postprocess -- version V3.1.0.0 -- Jan van Straaten" generator-info-url="http://www.webgrabplus.com">
<channel id="HBO HD">
<display-name lang="en">HBO HD</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="HBO Signature (HD)">
<display-name lang="en">HBO Signature (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="HBO Family (HD)">
<display-name lang="en">HBO Family (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="HBO Hits (HD)">
<display-name lang="en">HBO Hits (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="CINEMAX (HD)">
<display-name lang="en">CINEMAX (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="eGG Network">
<display-name lang="en">eGG Network</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="AFN (HD)">
<display-name lang="en">AFN (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="Nat Geo Wild HD">
<display-name lang="en">Nat Geo Wild HD</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="National Geographic (HD) ">
<display-name lang="en">National Geographic (HD) </display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="Discovery Channel (HD)">
<display-name lang="en">Discovery Channel (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="Nat Geo People HD">
<display-name lang="en">Nat Geo People HD</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="FOX Action Movies (HD)">
<display-name lang="en">FOX Action Movies (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="TLC">
<display-name lang="en">TLC</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="tvN HD (Mandarin)">
<display-name lang="en">tvN HD (Mandarin)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="KBS World (HD)">
<display-name lang="en">KBS World (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<channel id="Warner TV (HD)">
<display-name lang="en">Warner TV (HD)</display-name>
<url>http://www.singteltv.com.sg</url>
</channel>
<programme start="20210924003500  0800" stop="20210924020500  0800" channel="HBO HD">
<title lang="en">AN AMERICAN PICKLE</title>
<desc lang="en">An immigrant worker falls into a vat of pickles and is brined for 100 years. The brine preserves him perfectly, and when he emerges in present day Brooklyn, he finds that he hasn't aged a day.(n)</desc>
</programme>
<programme start="20210924020500  0800" stop="20210924041000  0800" channel="HBO HD">
<title lang="en">QUEEN & SLIM</title>
<desc lang="en">On a first date, a black man and woman are stopped by a policeman over a minor traffic infraction. As the situation spirals, the man kills the officer in self-defense, forcing the two to go on the run.(n)</desc>
</programme>
<programme start="20210924041000  0800" stop="20210924060000  0800" channel="HBO HD">
<title lang="en">THE LOST HUSBAND</title>
<desc lang="en">Trying to put her life back together after the death of her husband, Libby and her children move to her estranged Aunt's goat farm in central Texas.(n)</desc>
</programme>
<programme start="20210924060000  0800" stop="20210924073500  0800" channel="HBO HD">
<title lang="en">RISE OF THE GUARDIANS</title>
<desc lang="en">Santa Claus, Easter Bunny, Tooth Fairy, Jack Frost and Sandman join forces to protect children's imagination from the evil Pitch!(n)</desc>
</programme>
<programme start="20210924073500  0800" stop="20210924091000  0800" channel="HBO HD">
<title lang="en">THE ADVENTURES OF SHARK BOY AND LAVA GIRL</title>
<desc lang="en">A boy's imaginary superhero friends come to life and join him on a series of adventures.(n)</desc>
</programme>
<programme start="20210924091000  0800" stop="20210924103000  0800" channel="HBO HD">
<title lang="en">LIKE A BOSS</title>
<desc lang="en">Two female friends with very different ideals decide to start a beauty company together. One is more practical, while the other wants to earn her fortune and live a lavish lifestyle.(n)</desc>
</programme>
<programme start="20210924103000  0800" stop="20210924121000  0800" channel="HBO HD">
<title lang="en">RED RIDING HOOD (2011)</title>
<desc lang="en">A young girl falls for an orphaned woodcutter, much to her family's displeasure.(n)</desc>
</programme>
<programme start="20210924121000  0800" stop="20210924141000  0800" channel="HBO HD">
<title lang="en">CHAPPIE</title>
<desc lang="en">Set in the future, a robot programmed with the ability to think and feel for himself becomes the target of destructive forces.(n)</desc>
</programme>
<programme start="20210924141000  0800" stop="20210924160500  0800" channel="HBO HD">
<title lang="en">GREEN LANTERN</title>
<desc lang="en">A test pilot is bestowed with superhero powers and is tasked with keeping peace within the universe. Ryan Reynolds in the “Green Lantern.”.(n)</desc>
</programme>
<programme start="20210924160500  0800" stop="20210924173000  0800" channel="HBO HD">
<title lang="en">SCOOBY-DOO</title>
<desc lang="en">The lovable crime-fighting mutt makes his big screen debut alongside Sarah Michelle Gellar and Freddie Prinze Jr.(n)</desc>
</programme>
<programme start="20210924173000  0800" stop="20210924190500  0800" channel="HBO HD">
<title lang="en">SONIC THE HEDGEHOG</title>
<desc lang="en">The (mis)adventures of Sonic as he navigates the complexities of life on Earth with his newfound human best friend. Together, they must stop Dr. Robotnik from using Sonic's immense powers for world domination.(n)</desc>
</programme>
<programme start="20210924190500  0800" stop="20210924210000  0800" channel="HBO HD">
<title lang="en">KONG: SKULL ISLAND</title>
<desc lang="en">A team of scientists, soldiers and adventurers unite to explore a mythical, uncharted island where they ignite the ultimate battle between man and nature.(n)</desc>
</programme>
<programme start="20210924210000  0800" stop="20210924230000  0800" channel="HBO HD">
<title lang="en">BAD BOYS FOR LIFE</title>
<desc lang="en">The Bad Boys Mike Lowrey (Will Smith) and Marcus Burnett (Martin Lawrence) are back together for one last ride in the highly anticipated Bad Boys for Life.(n)</desc>
</programme>
<programme start="20210924230000  0800" stop="20210924230000  0800" channel="HBO HD">
<title lang="en">THE GRUDGE (2020)</title>
<desc lang="en">A curse born in Japan is simultaneously unleashed in the U.S. Those who encounter it are consumed by its fury and met with a violent fate.(n)</desc>
</programme>
<programme start="20210924230000  0800" stop="20210925003000  0800" channel="HBO HD">
<title lang="en">THE GRUDGE (2020)</title>
<desc lang="en">A curse born in Japan is simultaneously unleashed in the U.S. Those who encounter it are consumed by its fury and met with a violent fate.(n)</desc>
</programme>
<programme start="20210925003000  0800" stop="20210925021000  0800" channel="HBO HD">
<title lang="en">FREAKY</title>
<desc lang="en">Millie is just trying to survive high school when she becomes The Butcher's target. Their encounter gets twisted and they wake up in each other's bodies, with only 24 hours to reverse the curse.(n)</desc>
</programme>
<programme start="20210925021000  0800" stop="20210925040500  0800" channel="HBO HD">
<title lang="en">FOOTLOOSE (2011)</title>
<desc lang="en">A city kid moves to a small town where rock 'n' roll and dancing had been banned, and his rebellious spirit shakes up the populace.(n)</desc>
</programme>
<programme start="20210925040500  0800" stop="20210925053500  0800" channel="HBO HD">
<title lang="en">THE PARTS YOU LOSE</title>
<desc lang="en">A deaf boy and an injured stranger he helped form an unlikely paternal bond. But as the police presence begins to grow, he sees a darker side of the man and finds himself choosing between loyalty and what is right.(n)</desc>
</programme>
<programme start="20210925053500  0800" stop="20210925060000  0800" channel="HBO HD">
<title lang="en">HOLLYWOOD ON SET S1</title>
<desc lang="en">Go behind the scenes of three major motion pictures per week; catch action footage and interviews with actors and filmmakers.(n)</desc>
</programme>
<programme start="20210925060000  0800" stop="20210925072000  0800" channel="HBO HD">
<title lang="en">TEEN TITANS GO! VS. TEEN TITANS</title>
<desc lang="en">The Teen Titans and their taller and more serious selves must set aside their differences and work together to stop the mysterious “Master of Games”.(n)</desc>
</programme>
<programme start="20210925072000  0800" stop="20210925085000  0800" channel="HBO HD">
<title lang="en">ANCHORMAN: THE LEGEND OF RON BURGUNDY</title>
<desc lang="en">San Diego's top rated newsman gets threatened by a new female employee with ambition to burn.(n)</desc>
</programme>
<programme start="20210925085000  0800" stop="20210925102000  0800" channel="HBO HD">
<title lang="en">SMURFS: THE LOST VILLAGE</title>
<desc lang="en">Smurfette and Brainy, Clumsy, and Hefty are on an exciting and thrilling race through the Forbidden Forest to find the lost village.(n)</desc>
</programme>
<programme start="20210925102000  0800" stop="20210925115500  0800" channel="HBO HD">
<title lang="en">BIG MOMMA'S HOUSE</title>
<desc lang="en">To make a key arrest, FBI agent Malcolm Turner must disguise himself convincingly as the outsized grandmother of an escaped convict's ex-girlfriend.(n)</desc>
</programme>
<programme start="20210925115500  0800" stop="20210925133500  0800" channel="HBO HD">
<title lang="en">BIG MOMMA'S HOUSE 2</title>
<desc lang="en">Once again donning a disguise as granny Big Momma, FBI agent Malcolm Turner goes undercover to stop a national security threat in this sequel.(n)</desc>
</programme>
<programme start="20210929144500  0800" stop="20210929151000  0800" channel="Warner TV (HD)">
<title lang="en">Young Sheldon S3</title>
<desc lang="en">In the season three finale, Sheldon discovers that Mary's been keeping a secret about his future. Also, Meemaw is furious when she learns that Dale fired Georgie.(n)</desc>
</programme>
<programme start="20210929151000  0800" stop="20210929153500  0800" channel="Warner TV (HD)">
<title lang="en">Container Wars S2</title>
<desc lang="en">A mysterious container from Guam has the competition ready for battle. Manic Matt fires a warning shot, but the Israelis aren't backing down. Will this enormous gamble pay off? Or will the container's questionable contents backfire?(n)</desc>
</programme>
<programme start="20210929153500  0800" stop="20210929160000  0800" channel="Warner TV (HD)">
<title lang="en">Container Wars S2</title>
<desc lang="en">The mother lode of all containers makes landfall. Jason and Matt go all in, but will their hunches pay off? Or will beauty queen Deana's fashion sense reel in the ultimate score? A surprise twist could change every rule in the book.(n)</desc>
</programme>
<programme start="20210930103500  0800" stop="20210930110000  0800" channel="Warner TV (HD)">
<title lang="en">The Big Bang Theory S10</title>
<desc lang="en">On the tenth season finale, the gang is concerned when Sheldon's former admirer, Dr. Ramona Nowitzki (returning guest star RIKI LINDHOME) resurfaces while Amy is away at Princeton.(n)</desc>
</programme>
<programme start="20210930110000  0800" stop="20210930112500  0800" channel="Warner TV (HD)">
<title lang="en">Container Wars S2</title>
<desc lang="en">Jason's got the inside track on a container that could have him coasting to paradise, but will some rotten contents spoil his score?(n)</desc>
</programme>
<programme start="20210930112500  0800" stop="20210930115000  0800" channel="Warner TV (HD)">
<title lang="en">Container Wars S2</title>
<desc lang="en">A squabble over the contents of a mysterious container threatens to destroy Mo & Ty's partnership for good. Will this be the last hurrah for Team Muscle?(n)</desc>
</programme>
</tv>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

I am not sure about what you want to do exactly.

Let say your have a JSON data file accessible by a simple GET request (as it seems to be) and want to convert it into an XML file using PHP.

First, you can convert your json to array with json_decode. Then, you can SimpleXML extension to generate an XML output.

As an example:

<?php

// 1. Get your JSON data
$json = file_get_contents('https://www.example.com/your-source.json');

// 2. Convert your JSON into an array
$array = json_decode($json);

// 3. Convert your array into XML
$xml = new SimpleXMLElement('<root/>');

foreach ($array as $key => $value) {
    if (!is_array($value)) {
        $xml->addChild($key, $value);
    }
}

// 4. Print your result
print($xml->asXML());

Of course, in this example, the third part has to be adapted to fit your needs, with childs and attributes you want (based on the SimpleXML documentation provided before).

  • Related