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?

    Well, I'm not surprised you're having trouble. You're trying to handle a list of strings like it was XML. Or is the "input" not what you say the input is? For example, I don't see anything with an id of "time3", so what is supposed to be in [font=monospace]$time_arr[/font]?

         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;
    

    So the only [font=monospace]$programme_title[/font] you're interested in is the last one?

    That is some very confused code: according to your description you're reading text and outputting XML. But from your code you're trying to read HTML and output XML (there is something called XSLT, by the way). Don't you have your data in any more usable form than that?

    How much of what you're trying to do is just a rehash of what XMLTV has already done?

    Also, see RFC 2606.

      Yeah I did have a bit of trouble with the loops. I'm only interested in $programme_title. When I used this code:

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

      I will get the list of strings like this which it should be more than that:

      Paid ProgrammingThe Mentalist - Black HeartsAnthony Bourdain Parts Unknown - RussiaNFL LiveStosselBad Dog! - Bad to the BoneHouse - Son of Coma GuyCutlery Corner WildThe Real Housewives of Atlanta - Secrets RevealedThe Real Housewives of Atlanta - Secrets RevealedThe Real Housewives of Atlanta - Secrets RevealedThe Real Housewives of Atlanta - Secrets RevealedThe Real Housewives of Atlanta - Secrets RevealedThe Real Housewives of Atlanta - Secrets RevealedThe Real Housewives of Atlanta - Secrets RevealedThe Real Housewives of Atlanta - Secrets Revealed

      So if I try this:

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

      I will get the short list of the strings.

      When I use this code:

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

      I will get the large list of strings:

      Step Up 3The 700 ClubThe Fresh Prince of Bel-Air - Not With My Cousin You Don'tThe Fresh Prince of Bel-Air - Viva Lost WagesThe Fresh Prince of Bel-Air - There's the RubThe Fresh Prince of Bel-Air - There's the RubSummer Sexy With T25!Dr. Ordon's Secret!The 700 ClubAirbrushed BeautySleep Better!Joseph PrinceLife Today With James Robison - SMF Special 1Joyce Meyer: Enjoying Everyday LifeShaun T's Focus T25That '70s Show - The Velvet RopeThat '70s Show - Laurie and the ProfessorThat '70s Show - HalloweenThat '70s Show - Van StockStill Standing - Still Mother's Day700 Club InteractiveThe 700 ClubGilmore Girls - Those Lazy-Hazy-Crazy Days8 Simple Rules - Let's Keep Going8 Simple Rules - C.J.'s PartyReba - Don't Know Much About HistoryReba - Every Picture Tells a StoryReba - When Good Credit Goes BadReba - Meet the ParentsBoy Meets World - Heartbreak CoryBoy Meets World - First Girlfriends' ClubBoy Meets World - Torn Between Two Lovers (Feeling Like a Fool)Boy Meets World - And Then There Was ShawnThe Middle - The HoseThe Middle - Halloween III - The DrivingThe Middle - The SafeThe Middle - Twenty YearsLetters to JulietThe 700 ClubThe Fresh Prince of Bel-Air - Mother's DayThe Fresh Prince of Bel-Air - I, Ooh, Baby, BabyThe Fresh Prince of Bel-Air - Boxing HelenaThe Fresh Prince of Bel-Air - I, ClowniusShaun T's Focus T25Total Gym for $14.95The 700 ClubPaid ProgrammingBetter Carpet Cleaning at 1/3 the Price!Remove unwanted hair, permanently, painlessly at homeDr. Ordon's Secret!Summer Sexy With T25!Paid ProgrammingLetters to JulietUnder the Tuscan SunSecretariatSister ActSister Act 2: Back in the HabitMamma Mia!Forrest Gump(D,L,V,S)SpanglishPhil Collins, Rod Stewart, Celine Dion, Lionel RichieForeigner, Peter Frampton, ChicagoThe T-Fal OptiGrill - Grill like a ProShaun T's Focus T25Total Gym for $14.95Paid ProgrammingBarefoot CleanZola Levitt PresentsPaid ProgrammingTwo and a Half Men - Oh, WALD-E, Good Times AheadBad Teacher - Evaluation DayElementary - Art in the BloodLocal ProgrammingLate Show With David LettermanThe Late Late Show With Craig FergusonLocal ProgrammingUp to the MinuteCBS Morning NewsCBS Morning NewsCBS Morning NewsCBS Morning NewsLocal ProgrammingCBS This MorningLocal ProgrammingThe Price Is RightLocal ProgrammingThe Young and the RestlessThe Bold and the BeautifulThe TalkLet's Make a DealLocal ProgrammingCBS Evening News With Scott PelleyUnforgettable - ReunionHawaii Five-0 - O ka Pili 'Ohana ka 'OiBlue Bloods - ExilesLocal ProgrammingLate Show With David LettermanThe Late Late Show With Craig FergusonLocal ProgrammingLocal ProgrammingLucky Dog - BaileyDr. Chris Pet Vet - Family FeudCBS This Morning: SaturdayRecipe Rehab - Carrot CakeJamie Oliver's 15 Minute Meals - Pork Marsala and Thai NoodlesAll In With Laila Ali - Faster Than the WindGame Changers With Kevin Frazier - World Cup FeverLocal ProgrammingLocal ProgrammingLocal ProgrammingLocal ProgrammingLocal ProgrammingCBS Evening NewsMike & Molly - Poker in the Front, Looker in the BackThe Millers - The Phone Upgrade48 Hours - Ambushed48 Hours - A Raging SonLocal ProgrammingLocal ProgrammingLocal ProgrammingLocal ProgrammingLocal ProgrammingLocal ProgrammingCBS News Sunday MorningFace the NationLocal ProgrammingLocal ProgrammingLocal ProgrammingLocal ProgrammingFishing - 2014 Challenge Cup ChampionshipBull Riding - PBR Last Cowboy StandingLocal ProgrammingLocal ProgrammingCBS Evening News60 MinutesThe Amazing Race - Hei Ho Heidi HoThe Good Wife - The One PercentThe Mentalist - Black HeartsCNN Special ReportAnderson Cooper 360CNN TonightCNN Special ReportAnderson Cooper 360CNNI SimulcastEarly Start With John Berman and Christine RomansEarly Start With John Berman and Christine RomansNew DayCNN NewsroomAt This Hour With Berman and MichaelaLegal View With Ashleigh BanfieldWolfCNN NewsroomThe Lead With Jake TapperThe Situation RoomCrossfireErin Burnett OutFrontAnderson Cooper 360CNN TonightCNN Spotlight - Whitney HoustonAnthony Bourdain Parts Unknown - Lyon, FranceAnthony Bourdain Parts Unknown - Mexico CityCNN Spotlight - Angelina JolieCNN Spotlight - Whitney HoustonAnthony Bourdain Parts Unknown - Lyon, FranceAnthony Bourdain Parts Unknown - Mexico CityAnthony Bourdain Parts Unknown - Las VegasCNNI SimulcastNew Day SaturdaySmerconishCNN NewsroomYour MoneyCNN NewsroomCNN NewsroomSanjay Gupta, MDCNN NewsroomCNN NewsroomCNN NewsroomAnthony Bourdain Parts Unknown - Las VegasAnthony Bourdain Parts Unknown - Lyon, FranceAnthony Bourdain Parts Unknown - Mexico CityAnthony Bourdain Parts Unknown - Las VegasAnthony Bourdain Parts Unknown - Lyon, FranceAnthony Bourdain Parts Unknown - Mexico CityAnthony Bourdain Parts Unknown - Las VegasAnthony Bourdain Parts Unknown - Lyon, FranceAnthony Bourdain Parts Unknown - Mexico CityCNNI SimulcastNew Day SundaySanjay Gupta, MDNew Day SundayInside PoliticsState of the Union With Candy CrowleyFareed Zakaria GPSReliable SourcesState of the Union With Candy CrowleyFareed Zakaria GPSCNN NewsroomCNN NewsroomCNN NewsroomCNN NewsroomCNN NewsroomCNN NewsroomAnthony Bourdain Parts Unknown - Mexico CityAnthony Bourdain Parts Unknown - RussiaMorgan Spurlock Inside Man - The book of MorganAnthony Bourdain Parts Unknown - Mexico CityAnthony Bourdain Parts Unknown - Russia2014 NFL Draft - First RoundSportsCenterSportsCenterSportsCenterNBA Basketball - Brooklyn Nets at Miami 

      So how do you store the variable to allow me to put the $programme_title variable under the foreach $time_arr so I can print the large list of strings like above?

        Write a Reply...