Jump to content

how do i get each different strings to output them


mark107

Recommended Posts

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 what 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 strings to output them without output the same strings?

Link to post
Share on other sites

I'm showing you the output of the xml tree, can you see at the <title lang="en"></title> where each of them I'm getting the same strings called "Reba - Meet the Parents"?

 

do you know how I can output each of these strings from the arrays like this?

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