Jump to content

Problem with output the contents when generating XML


mark107

Recommended Posts

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:

 



   <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:

 



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


 

 

 

Here's the CBS programme info:

 



    4:00 PM - The Talk
    
    5:00 PM - Let's 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:

 



   <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
    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-]", "",
      strtolower( str_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. 

Link to post
Share on other sites

no one has answered this because your code is a thrown together mess that no one can figure out what it is doing, so no one can tell you what's wrong with it. you also did not provide the actual html input data that corresponds to the desired output, that would be needed to experiment with the code (no one here is going to reverse engineer what the code is doing in order to come up with sample input data.)

 

you have variables and functions that are not used; variables used as array indexes that are both not initialized, nor incremented; code repeated four times, that only differs in the input variables it uses; code that's retrieving all the html data (apparently from your own site), then inside the loop that's processing that data, gets more data from your own site; and i suspect a lot of the code isn't even being used to produce the output xml data, it's just left over from some example you copy/pasted.

 

you need to start by writing (rather than copy/pasting) just the code you need that will get the job done.

 

you also need to answer a question that has been asked before. are you getting this html from your own site (in which case you should be just using the original data that is producing the html) or are you just posting a dummy url that makes us think you are getting the html from your own site?

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.