Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem with output the contents when generating XML

    Hi all,

    I need your help, I'm working on my php to get the list of contents from my get-listing.php script so I can generating the XML to output the contents into the XML.

    I have got a little bit of problem with output the contents. I'm still getting the same contents in the XML output for each channel when I generating the XML.


    Here is the XML:

    Code:
        <tv generator-info-name="www.mysite.com/myXML">
        <channel id="101 ABC FAMILY">
        <display-name>101 ABC FAMILY</display-name>
        <programme channel="101 ABC FAMILY" start="20140418160000" stop="20140418163000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="101 ABC FAMILY" start="20140418163000" stop="20140418170000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="101 ABC FAMILY" start="20140418170000" stop="20140418173000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        </channel>
        
        <channel id="102 CBS">
        <display-name>102 CBS</display-name>
        <programme channel="102 CBS" start="20140418160000" stop="20140418163000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="102 CBS" start="20140418163000" stop="20140418170000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="102 CBS" start="20140418170000" stop="20140418173000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>



    Here's the ABC Family programme info:

    PHP Code:
       4:00 PM Boy Meets World Home
        
        4
    :30 PM Boy Meets World My Best Friends Girl
        
        5
    :00 PM The Middle The Big Chill
        
        5
    :30 PM The Middle FriendsLies and Videotape 


    Here's the CBS programme info:

    PHP Code:
       4:00 PM The Talk
        
        5
    :00 PM Lets Make a Deal
        
        6
    :00 PM Local Programming
        
        8
    :30 PM CBS Evening News With Scott Pelley 


    As you can see that on both channel programme info, it have got different time in each array. On mine it will show the same programme time for both channels when I'm generating the XML.

    Here is what it supposed to be:

    Code:
        <tv generator-info-name="www.mysite.com/myXML">
        <channel id="101 ABC FAMILY">
        <display-name>101 ABC FAMILY</display-name>
        <programme channel="101 ABC FAMILY" start="20140418160000" stop="20140418163000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="101 ABC FAMILY" start="20140418163000" stop="20140418170000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="101 ABC FAMILY" start="20140418170000" stop="20140418173000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        </channel>
        
        <channel id="102 CBS">
        <display-name>102 CBS</display-name>
        <programme channel="102 CBS" start="20140418160000" stop="20140418170000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="102 CBS" start="20140418170000" stop="20140418180000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        <programme channel="102 CBS" start="20140418180000" stop="20140418203000">
        <title lang="en"></title>
        <sub-title lang="en"></sub-title>
        <desc lang="en"></desc>
        <category lang="en"></category>
        </programme>
        </tv>


    Here is the PHP:

    PHP Code:
        <?php
        ini_set
    ('max_execution_time'300);
        
    $errmsg_arr = array();
        
    $errflag false;
        include (
    'simple_html_dom.php');
        
        function 
    getUrlFriendlyString($str)
        {
          
    // convert spaces to '-', remove characters that are not alphanumeric
          // or a '-', combine multiple dashes (i.e., '---') into one dash '-'.
          
    $str ereg_replace("[-]+""-"ereg_replace("[^a-z0-9-]""",
          
    strtolowerstr_replace(" ""-"$str) ) ) );
          return 
    $str;
        }
        
        function 
    getPaddedHour($hour$meridian
        {
          
    $ret $hour;
          if (
    $meridian == 'AM' && $ret == 12
          { 
            
    $ret 0;
          } 
          else if (
    $meridian == 'PM' && $ret != 12
          { 
            
    $ret += 11;
          }
          if (
    $ret 10
          {
            
    $ret '0'.$ret;
          }
          return 
    $ret;
        }
          
    $xml .= '<?xml version="1.0" encoding="UTF-8" ?>';
          
    $xml .= '
        <tv generator-info-name="www.testbox.elementfx.com/test">'
    ;
          
    $base1 "http://www.mysite.com/get-listing.php";
          
    $html file_get_html($base1);          
          
    //echo $xml;
        
        
    foreach($html->find('p[id=links]') as $element)
        {
          
    $program_list$count ] = array();
          
    $id_split explode("?"$element->plaintext);
          
    $id_split explode("&"$link_split[1]);
          
    $channels explode("channels=",$id_split[0]);
          
    $channels $channels[1];
          
    $id explode("id=",$id_split[1]);
          
    $id $id[1];
        
          
    //channels
          //$channel_test = $html->find('p[id=channels]', 10)->plaintext;
          //echo $channel_test;
        
          
    $program_list$count ]['channels'] = $channels;
          
    $program_list$count ]['id'] = $id;
        
          
    $channels_split explode("?"$element->plaintext);
          
    $channels_split explode("&"$channels_split[1]);
          
    $channel_id explode("channels=",$channels_split[0]);
          
    $channel_id $channel_id[1];
          
    $my_id explode("id=",$channels_split[1]);
          
    $my_id $my_id[1];
        
          
    $channel urlencode($channel_id);
          
    $id_1 urlencode($my_id);
          
    $html_two file_get_html("http://www.mysite.com/get-listing.php?channels=" $channel "&id=" $my_id);
        
          
    //time1
          
    $time1 $html_two->find('span[id=time1]',0)->plaintext;
          
    $title1 $html_two->find('span[id=title1]',0)->plaintext;
          
          
    $hoursMinutes explode(":"$time1[0]);
          
    $hours $hoursMinutes[0];
          
    $minutes $hoursMinutes[1];
          
          
    $time1 explode(" "$time1);
          
    $hoursMinutes explode(":"$time1[0]);
          
    $hours $hoursMinutes[0];
          
    $minutes $hoursMinutes[1];
        
          if(
    $time1[1] == "PM")
          {
            
    $time1[0] = date("Ymd") . ((int)($hours) + 12) . $minutes "00";
          } 
          else 
          {
            if(
    $hours=="12")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else if(
    $hours=="1")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "01" $minutes "00";
            }
            else if(
    $hours=="2")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "02" $minutes "00";
            }
            else if(
    $hours=="3")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "03" $minutes "00";
            }
            else if(
    $hours=="4")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "04" $minutes "00";
            }
            else if(
    $hours=="5")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "05" $minutes "00";
            }
            else if(
    $hours=="6")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "06" $minutes "00";
            }
            else if(
    $hours=="7")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "07" $minutes "00";
            }
            else if(
    $hours=="8")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "08" $minutes "00";
            }
            else if(
    $hours=="9")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "09" $minutes "00";
            }
            else if(
    $hours=="10")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "10" $minutes "00";
            }
            else if(
    $hours=="11")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "11" $minutes "00";
            }
            else if(
    $hours=="24")
            {
              
    $time1[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else
            {
              
    $time1[0] = date("Ymd") . $hours $minutes "00";
            }
          }
        
          
    $program_list[$count]['start_time1'] = $time1[0];
          
    $program_list[$count]['title1'] = $title1;
        
          
    //time2
          
    $time2 $html_two->find('span[id=time2]',0)->plaintext;
          
    $title2 $html_two->find('span[id=title2]',0)->plaintext;
         
          
    $time2 explode(" "$time2);
          
    $hoursMinutes explode(":"$time2[0]);
          
    $hours $hoursMinutes[0];
          
    $minutes $hoursMinutes[1];
        
          if(
    $time2[1] == "PM")
          {
            
    $time2[0] = date("Ymd") . ((int)($hours) + 12) . $minutes "00";
          } 
          else 
          {
            if(
    $hours=="12")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else if(
    $hours=="1")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "01" $minutes "00";
            }
            else if(
    $hours=="2")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "02" $minutes "00";
            }
            else if(
    $hours=="3")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "03" $minutes "00";
            }
            else if(
    $hours=="4")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "04" $minutes "00";
            }
            else if(
    $hours=="5")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "05" $minutes "00";
            }
            else if(
    $hours=="6")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "06" $minutes "00";
            }
            else if(
    $hours=="7")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "07" $minutes "00";
            }
            else if(
    $hours=="8")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "08" $minutes "00";
            }
            else if(
    $hours=="9")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "09" $minutes "00";
            }
            else if(
    $hours=="10")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "10" $minutes "00";
            }
            else if(
    $hours=="11")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "11" $minutes "00";
            }
            else if(
    $hours=="24")
            {
              
    $time2[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else
            {
              
    $time2[0] = date("Ymd") . $hours $minutes "00";
            }
          }
        
          
    $program_list[$count]['end_time1'] = $time2[0];
          
    $program_list[$count]['start_time2'] = $time2[0];
          
    $program_list[$count]['title2'] = $title2;
        
          
    //time3
          
    $time3 $html_two->find('span[id=time3]',0)->plaintext;
          
    $title3 $html_two->find('span[id=title3]',0)->plaintext;
         
          
    $time3 explode(" "$time3);
          
    $hoursMinutes explode(":"$time3[0]);
          
    $hours $hoursMinutes[0];
          
    $minutes $hoursMinutes[1];
        
          if(
    $time3[1] == "PM")
          {
            
    $time3[0] = date("Ymd") . ((int)($hours) + 12) . $minutes "00";
          } 
          else 
          {
            if(
    $hours=="12")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else if(
    $hours=="1")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "01" $minutes "00";
            }
            else if(
    $hours=="2")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "02" $minutes "00";
            }
            else if(
    $hours=="3")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "03" $minutes "00";
            }
            else if(
    $hours=="4")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "04" $minutes "00";
            }
            else if(
    $hours=="5")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "05" $minutes "00";
            }
            else if(
    $hours=="6")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "06" $minutes "00";
            }
            else if(
    $hours=="7")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "07" $minutes "00";
            }
            else if(
    $hours=="8")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "08" $minutes "00";
            }
            else if(
    $hours=="9")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "09" $minutes "00";
            }
            else if(
    $hours=="10")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "10" $minutes "00";
            }
            else if(
    $hours=="11")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "11" $minutes "00";
            }
            else if(
    $hours=="24")
            {
              
    $time3[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else
            {
              
    $time3[0] = date("Ymd") . $hours $minutes "00";
            }
          }
        
          
    $program_list[$count]['end_time2'] = $time3[0];
          
    $program_list[$count]['start_time3'] = $time3[0];
          
    $program_list[$count]['title3'] = $title3;
        
          
    //time4
          
    $time4 $html_two->find('span[id=time4]',0)->plaintext;
          
    $title4 $html_two->find('span[id=title4]',0)->plaintext;
        
          
    $time4 explode(" "$time4);
          
    $hoursMinutes explode(":"$time4[0]);
          
    $hours $hoursMinutes[0];
          
    $minutes $hoursMinutes[1];
        
          if(
    $time4[1] == "PM")
          {
            
    $time4[0] = date("Ymd") . ((int)($hours) + 12) . $minutes "00";
          } 
          else 
          {
            if(
    $hours=="12")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else if(
    $hours=="1")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "01" $minutes "00";
            }
            else if(
    $hours=="2")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "02" $minutes "00";
            }
            else if(
    $hours=="3")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "03" $minutes "00";
            }
            else if(
    $hours=="4")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "04" $minutes "00";
            }
            else if(
    $hours=="5")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "05" $minutes "00";
            }
            else if(
    $hours=="6")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "06" $minutes "00";
            }
            else if(
    $hours=="7")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "07" $minutes "00";
            }
            else if(
    $hours=="8")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "08" $minutes "00";
            }
            else if(
    $hours=="9")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "09" $minutes "00";
            }
            else if(
    $hours=="10")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "10" $minutes "00";
            }
            else if(
    $hours=="11")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "11" $minutes "00";
            }
            else if(
    $hours=="24")
            {
              
    $time4[0] = date('Ymd'strtotime(' +1 day')) . "00" $minutes "00";
            }
            else
            {
              
    $time4[0] = date("Ymd") . $hours $minutes "00";
            }
          }
        
          
    $program_list[$count]['end_time3'] = $time4[0];
          
    $program_list[$count]['start_time4'] = $time4[0];
          
    $program_list[$count]['title4'] = $title4;

          if (
    strpos($channel'+') !== false)
          {
            
    $channel str_replace('+'' '$channel);
          }
          
          
    //program 1#
          
    $xml .= "
          <channel id='" 
    $my_id" " $channel "'>";
          
    $xml .= "
            <display-name>" 
    $my_id" " $channel
          
    $xml .= "</display-name>";
          
    $xml .= "
          <programme channel='" 
    $my_id" " $channel "' start='" $program_list[$i]['start_time1'] . "' stop='" $program_list[$i]['end_time1'] . "'>";
          
    $xml .= '
            <title lang="en">'
    ;
          
    $xml .= ' </title>';
          
    $xml .= '
            <sub-title lang="en">'
    ;
          
    $xml .= ' </sub-title>';
          
    $xml .= '
            <desc lang="en">'
    ;
          
    $xml .= ' </desc>';
          
    $xml .= '
            <category lang="en">'
    ;
          
    $xml .= ' </category>';
          
    $xml .= "
          </programme>"
    ;
        
        
          
    //program 2#
          
    $xml .= "
          <programme channel='" 
    $my_id" " $channel "' start='" $program_list[$i]['start_time2'] . "' stop='" $program_list[$i]['end_time2'] . "'>";
          
    $xml .= '
            <title lang="en">'
    ;
          
    $xml .= ' </title>';
          
    $xml .= '
            <sub-title lang="en">'
    ;
          
    $xml .= ' </sub-title>';
          
    $xml .= '
            <desc lang="en">'
    ;
          
    $xml .= ' </desc>';
          
    $xml .= '
            <category lang="en">'
    ;
          
    $xml .= ' </category>';
          
    $xml .= '
          </programme>'
    ;
        
        
          
    //program 3#
          
    $xml .= "
          <programme channel='" 
    $my_id" " $channel "' start='" $program_list[$i]['start_time3'] . "' stop='" $program_list[$i]['end_time3'] . "'>";
          
    $xml .= '
            <title lang="en">'
    ;
          
    $xml .= ' </title>';
          
    $xml .= '
            <sub-title lang="en">'
    ;
          
    $xml .= ' </sub-title>';
          
    $xml .= '
            <desc lang="en">'
    ;
          
    $xml .= ' </desc>';
          
    $xml .= '
            <category lang="en">'
    ;
          
    $xml .= ' </category>';
          
    $xml .= '
          </programme>'
    ;
        
        
          
    //program 4#
          
    $xml .= "
          <programme channel='" 
    $my_id" " $channel "' start='" $program_list[$i]['start_time4'] . "' stop='" $program_list[$i]['end_time4'] . "'>";
          
    $xml .= '
            <title lang="en">'
    ;
          
    $xml .= ' </title>';
          
    $xml .= '
            <sub-title lang="en">'
    ;
          
    $xml .= ' </sub-title>';
          
    $xml .= '
            <desc lang="en">'
    ;
          
    $xml .= ' </desc>';
          
    $xml .= '
            <category lang="en">'
    ;
          
    $xml .= ' </category>';
          
    $xml .= '
          </programme>'
    ;
        }
          
    $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);
        
    ?>

    Does anyone know how I can get the list of contents for each channel when I'm generating the XML without output the same contents on both channels tags in the XML?

    I think I have missing with something especially the integer.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    I've seen you posting this several times ... about the script you wrote to create the XML ... which is the script you're having a problem with ...

    I sure wish, I mean I really wish, I mean I truly truly wish, that you would post the PHP script that creates this:

    4:00 PM - Boy Meets World - Home
    4:30 PM - Boy Meets World - My Best Friends Girl
    5:00 PM - The Middle - The Big Chill
    5:30 PM - The Middle - Friends, Lies and Videotape


    You said that you have the PHP script that creates that "Programme Info" for ABC/CBS (etc), but you never post that script. Why?

    Why can't you post that script?

    I don't mean the script you're posting about the XML file, I mean the script that outputs the "Programme Info".

    Why?

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    I've seen you posting this several times ... about the script you wrote to create the XML ... which is the script you're having a problem with ...

    I sure wish, I mean I really wish, I mean I truly truly wish, that you would post the PHP script that creates this:

    4:00 PM - Boy Meets World - Home
    4:30 PM - Boy Meets World - My Best Friends Girl
    5:00 PM - The Middle - The Big Chill
    5:30 PM - The Middle - Friends, Lies and Videotape


    You said that you have the PHP script that creates that "Programme Info" for ABC/CBS (etc), but you never post that script. Why?

    Why can't you post that script?

    I don't mean the script you're posting about the XML file, I mean the script that outputs the "Programme Info".

    Why?
    Because it has got nothing to do with generating the XML. This script I post it has got to do with it.

    Why do you need to see it anyway?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    Yes it does have something to do with the XML you're trying to create ...

    Don't you see?

    If that script can generate this ...

    4:00 PM - Boy Meets World - Home
    4:30 PM - Boy Meets World - My Best Friends Girl
    5:00 PM - The Middle - The Big Chill
    5:30 PM - The Middle - Friends, Lies and Videotape

    Then it can generate the XML that you are trying so hard to create.


    Instead of outputting this ....

    4:00 PM - Boy Meets World - Home
    4:30 PM - Boy Meets World - My Best Friends Girl
    5:00 PM - The Middle - The Big Chill
    5:30 PM - The Middle - Friends, Lies and Videotape

    You can have it output your XML.

    The other script already goes to the TV Guide and grabs all of the information. It already parses that information and creates the "Programme List". Why not have it create your XML instead?

    Doesn't that seem like such an easier way? I think so.

    That means one script does what you want, instead of using two scripts to do it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •