Hi all,
I need your help, I'm working on my PHP as I want to get the list of links for each array in get-listing.php.
I want to get the list of links for each array like this:
http://testbox.elementfx.com/get-listing.php?channels=ABC FAMILY&id=101
http://testbox.elementfx.com/get-listing.php?channels=CBS&id=102
http://testbox.elementfx.com/get-listing.php?channels=CNN USA&id=103
http://testbox.elementfx.com/get-listing.php?channels=ESPN USA&id=105
..and so on
I want to connect on each link in my PHP for each array to get the list of programme info to output them in the XML source.
Here's for e.g:
http://testbox.elementfx.com/get-listing.php
I want to connect on get-listing.php and I want to connect on each link in the get-listing.php to get the cbs and cnn usa links then I want to get access on both links at a time to get the programme info.
CBS programme info:
<span id="time1">12:00 PM </span> - <span id="title1">2014 NCAA Basketball Tournament"Dayton vs. Ohio State - LIVE</span><br><br>
<span id="time2">2:30 PM </span> - <span id="title2">2014 NCAA Basketball Tournament"Western Michigan vs. Syracuse - LIVE</span><br><br>
<span id="time3">5:00 PM </span> - <span id="title3">Local Programming</span><br><br>
<span id="time4">6:00 PM </span> - <span id="title4">Local Programming</span><br><br>
<span id="time5">7:00 PM </span> - <span id="title5">2014 NCAA Basketball Tournament"Wofford vs. Michigan - LIVE</span><br><br>
<span id="time6">9:30 PM</span> - <span id="title6">2014 NCAA Basketball Tournament"Arizona State vs. Texas - LIVE</span><br><br>
<span id="time7">12:00 AM </span> - <span id="title7"> 1 Local Programming</span><br><br>
<span id="time8">12:35 AM </span> - <span id="title8">Late Show With David LettermanTV-PG </span><br><br>
<span id="time9">1:37 AM </span> - <span id=title9>The Late Late Show With Craig FergusonTV-14 </span><br><br>
CNN programme info:
<span id="time1">1:00 PM </span> - <span id="title1">Wolf</span><br><br>
<span id="time2">2:00 PM </span> - <span id="title2">CNN Newsroom</span><br><br>
<span id="time3">4:00 PM </span> - <span id="title3">The Lead With Jake Tapper</span><br><br>
<span id="time4">5:00 PM </span> - <span id="title4">The Situation Room</span><br><br>
<span id="time5">6:30 PM </span> - <span id="title5">Crossfire</span><br><br>
<span id="time6">7:00 PM </span> - <span id="title6">Erin Burnett OutFront</span><br><br>
<span id="time7">8:00 PM </span> - <span id="title7">Anderson Cooper 360</span><br><br>
<span id="time8">9:00 PM </span> - <span id="title8">Piers Morgan Live</span><br><br>
<span id="time9">10:00 PM </span> - <span id="title9">CNN Spotlight</span><br><br>
I want to get the list of programme info from each tag of <span id="title1
, <span id="title2
, <span id="title3
...etc to allow me to generating for each xml tag <programme channel="CHANNEL NAME" start="s1" stop="e1">
, <programme channel="CHANNEL NAME" start="s2" stop="e2">
with each different start and end times then output the programe title in each xml tag called <title lang="en">
.
The output for the XML would be looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<tv generator-info-name="www.testbox.elementfx.com/xmltv">
<channel id="CBS">
<display-name>CBS</display-name>
<programme channel="CBS" start="s1" stop="e1">
<title lang="en">2014 NCAA Basketball Tournament"Dayton vs. Ohio State - LIVE</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
<programme channel="CBS" start="s2" stop="e2">
<title lang="en">2014 NCAA Basketball Tournament"Western Michigan vs. Syracuse - LIVE</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
<programme channel="CBS" start="s3" stop="e3">
<title lang="en">Local Programming</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
<programme channel="CBS" start="s4" stop="e4">
<title lang="en">Local Programming</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
</channel>
<channel id="CNN USA">
<display-name>CNN USA</display-name>
<programme channel="CNN USA" start="s1" stop="e1">
<title lang="en">Wolf</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
<programme channel="CNN USA" start="s2" stop="e2">
<title lang="en">CNN Newsroom</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
<programme channel="CNN USA" start="s3" stop="e3">
<title lang="en">The Lead With Jake Tapper</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
<programme channel="CNN USA" start="s4" stop="e4">
<title lang="en">The Situation Room</title>
<sub-title lang="en">sub title</sub-title>
<desc lang="en">program description1</desc>
<category lang="en">some category</category>
</programme>
</channel>
</tv>
Here's the PHP script:
<?php
function db_connect()
{
define('DB_HOST', 'localhost');
define('DB_USER', 'myusername');
define('DB_PASSWORD', 'mypassword');
define('DB_DATABASE', 'mydbname');
$errmsg_arr = array();
$errflag = false;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link)
{
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db)
{
die("Unable to select database");
}
}
db_connect();
function clean($var)
{
return mysql_real_escape_string(strip_tags($var));
}
$channels = clean($_GET['channels']);
$id = clean($_GET['id']);
if($errflag)
{
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
echo implode('<br />',$errmsg_arr);
}
else
{
$insert = array();
if(isset($_GET['channels']))
{
$insert[] = 'channels = \'' . clean($_GET['channels']) .'\'';
}
if(isset($_GET['id']))
{
$insert[] = 'id = \'' . clean($_GET['id']) . '\'';
}
if(!$channels && ! $id)
{
$qrytable1="SELECT id, channels, links, streams FROM tvguide";
$result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
while ($row = mysql_fetch_array($result1))
{
// fake some example data. the actual data would be retrieved from a database query
$data[] = array('channel_id'=>$row['channels'],
'display_name'=>$row['channels'],
'program_id'=>123,'start'=>'s1','stop'=>'e1',
'title'=>'program title',
'sub_title'=>'sub title',
'description'=>'program description1',
'category'=>'some category');
// build the xml
$xml = '<?xml version="1.0" encoding="UTF-8" ?>
<tv generator-info-name="www.testbox.elementfx.com/xmltv">';
$last_channel = null; // used to detect when the channel changes
foreach($data as $arr)
{
if($last_channel != $arr['channel_id'])
{
// the channel changed
if($last_channel != null)
{
// not the first channel, close out the previous channel
$xml .= "
</channel> \n";
}
// start a new channel
$xml .= "
<channel id=\"{$arr['channel_id']}\">";
$xml .= "
<display-name>{$arr['display_name']}</display-name>";
$last_channel = $arr['channel_id'];
}
// output the program info under each channel
$xml .= "
<programme channel=\"{$arr['channel_id']}\" start=\"{$arr['start']}\" stop=\"{$arr['stop']}\">";
// i don't see a program id in this definition, but it likely needs one
$xml .= "
<title lang=\"en\">{$arr['title']}</title>";
$xml .= "
<sub-title lang=\"en\">{$arr['sub_title']}</sub-title>";
$xml .= "
<desc lang=\"en\">{$arr['description']}</desc>";
$xml .= "
<category lang=\"en\">{$arr['category']}</category>";
$xml .= "
</programme>";
}
if($last_channel != null)
{
// close out the previous channel if any
$xml .= '
</channel>';
}
}
}
$xml .= '
</tv>';
// output the xml to the browser in this example, write $xml to a file here...
header("Content-Type: text/xml");
echo $xml;
$handle = fopen("myChannel.xml", "w");
fwrite ($handle, $xml);
}
?>
Can you please tell me how I can do that using with my php source?
Thanks in advance