0

Hi all,

I need your help as I got a problem with the strings. When I get the list of strings for the input, I keep getting the same strings over and over when I output them.

Here is where you can see in the output:

<tv generator-info-name="www.mysite.com/xmltv">
<channel id="101 ABC FAMILY">
<display-name>101 ABC FAMILY</display-name>
<programme channel="101 ABC FAMILY" start="20140507180000" stop="
20140507183000">
<title lang="en">Reba - Meet the Parents</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507183000" stop="
20140507190000">
<title lang="en">Reba - Meet the Parents</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507190000" stop="
20140507193000">
<title lang="en">Reba - Meet the Parents</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507193000" stop="
20140507200000">
<title lang="en">Reba - Meet the Parents</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507200000" stop="
20140507203000">
<title lang="en">Reba - Meet the Parents</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507203000" stop="
20140507210000">
<title lang="en">Reba - Meet the Parents</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
</tv>

It supposed to be what it would look like:

<tv generator-info-name="www.mysite.com/xmltv">
<channel id="101 ABC FAMILY">
<display-name>101 ABC FAMILY</display-name>
<programme channel="101 ABC FAMILY" start="20140507180000" stop="
20140507183000">
<title lang="en">he Middle - The Telling</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507183000" stop="
20140507190000">
<title lang="en">he Middle - The Wedding</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507190000" stop="
20140507193000">
<title lang="en">Melissa & Joey - More Than Roommates</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507193000" stop="
20140507200000">
<title lang="en">Melissa & Joey - Accidents Will Happen</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507200000" stop="
20140507203000">
<title lang="en">Melissa & Joey - Right Time, Right Place</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY" start="20140507203000" stop="
20140507210000">
<title lang="en">Baby Daddy - Curious Georgie</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
</tv>

Here is the input:

The Middle - The Telling

The Middle - The Wedding

Melissa & Joey - More Than Roommates

Melissa & Joey - Accidents Will Happen

Melissa & Joey - Right Time, Right Place

Baby Daddy - Curious Georgie

John Tucker Must Die(D,L,V,S)

The 700 Club

Baby Daddy - From Here to Paternity

Reba - Meet the Parents

Here is the PHP:

<?php
ini_set('max_execution_time', 300);
$errmsg_arr = array();
$errflag = false;


function getState($string)
{
  $ex = explode(" ",$string);
  return $ex[1];
}

$xml .= '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '
<tv generator-info-name="www.mysite.com/xmltv">';
$baseUrl = file_get_contents('http://www.myownsite.com/get-listing.php'
);

$domdoc = new DOMDocument();
$domdoc->strictErrorChecking = false;
$domdoc->recover=true;
@$domdoc->loadHTML($baseUrl);
$links = $domdoc->getElementsByTagName('a');
$i = 0;
$count = 0;

$data = array();
foreach($links as $link)
{
  if($link->getAttribute('href'))
  {
    if(!$link->hasAttribute('id') || $link->getAttribute('id')!='streams')
    {
      $url = str_replace("rtmp://", "", $link->getAttribute('href'));
      $url = str_replace(" ", "%20", $link->getAttribute('href'));
      $sdoc = new DOMDocument();
      $sdoc->strictErrorChecking = false;
      $sdoc->recover=true;
      @$sdoc->loadHTMLFile($url);
      $query = parse_url($url)['query'];
      $channel_split = explode("&", $query)[0];
      $channel = urldecode(explode("=",$channel_split)[1]);
      $id_split = explode("&", $query)[1];
      $my_id = urldecode(explode("=",$id_split)[1]);
      $xpath = new DOMXpath($sdoc);      
      $programme_arr = array();     
      $time_arr = array();

      for ($i = 1; $i < 70; $i++)
      {
        $time_arr[] = $xpath->query("*/span[@id='time".$i."']");
        $programme_arr[] = $xpath->query("*/span[@id='title".$i."']");
      }

      foreach($programme_arr as $programme)
      {
        $programme1 = $programme->item(0)->nodeValue;
      }
      $programme_title = $programme1;


      // Generating to make the XML File
      $xml .= "
  <channel id='" . $my_id. " " . $channel . "'>";
      $xml .= "
    <display-name>" . $my_id. " " . $channel; 
      $xml .= " </display-name>";

      // Save the output format
      $DATE_FORMAT_STRING = "YmdHis";

      // GET the current STAGE
      $current_state = getState($array[0]->nodeValue);
      $offset = 0;
      $flag = 0;

      foreach($time_arr as $time)
      {
        // Get the item state.  
        $this_state = getState($time->item(0)->nodeValue);

        // check if we past a day? 
        if($current_state == "PM" && $this_state == "AM")
        {
          $offset++;
        }
        $this_unix = strtotime($time->item(0)->nodeValue) + (60 * 60 * 24 * 
$offset);
        $values[] = date($DATE_FORMAT_STRING, $this_unix);
        $starttime = $values[$count];

        if($flag>0)
        {
          $xml .= '
  <programme channel="'.$my_id. ' ' .$channel.'" start="'.$stoptime.'" 
stop="'.$starttime.'">';
          $xml .= '<title lang="en">'.$programme_title;
          $xml .= ' </title>';

          $xml .= '
    <sub-title lang="en">';
          $xml .= ' </sub-title>';
          $xml .= '
    <desc lang="en">';
          $xml .= ' </desc>';
          $xml .= '
    <category lang="en">';
          $xml .= ' </category>';
          $xml .= '
  </programme>';
          $stoptime = $starttime;
        }
        else
        {
          $stoptime = $starttime;
          $flag=1;
        } 
        $current_state = $this_state;
        $count++;
      }

      $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 get each different strings for the output without output the same strings?

1
Contributor
1
Reply
19
Views
3 Years
Discussion Span
Last Post by mark103
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.