1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Output PHP in xml

Discussion in 'PHP' started by mark103, Mar 21, 2014.

  1. #1
    Hi all,

    I need your help. I want to get access on each PHP link for each array to get the list of programme title to output them in the XML source.

    Here's for e.g:

    http://testbox.elementfx.com/get-listing.php


    I want to access to get-listing.php and I want to get the cbs link to access and get the list of programming info:


        <span id="time1">12:00 PM </span> - <span id="title1">2014 NCAA Basketball Tournament"Dayton vs. Ohio State - LIVE</span><br><br>
        <span id="time2">2:30 PM </span> - <span id="title2">2014 NCAA Basketball Tournament"Western Michigan vs. Syracuse - LIVE</span><br><br>
        <span id="time3">5:00 PM </span> - <span id="title3">Local Programming</span><br><br>
        <span id="time4">6:00 PM </span> - <span id="title4">Local Programming</span><br><br>
        <span id="time5">7:00 PM </span> - <span id="title5">2014 NCAA Basketball Tournament"Wofford vs. Michigan - LIVE</span><br><br>
        <span id="time6">9:30 PM</span> - <span id="title6">2014 NCAA Basketball Tournament"Arizona State vs. Texas - LIVE</span><br><br>
        <span id="time7">12:00 AM </span> - <span id="title7"> 1 Local Programming</span><br><br>
        <span id="time8">12:35 AM </span> - <span id="title8">Late Show With David LettermanTV-PG  </span><br><br>
        <span id="time9">1:37 AM </span> - <span id=title9>The Late Late Show With Craig FergusonTV-14  </span><br><br>
    Code (markup):

    CBS link: http://testbox.elementfx.com/get-listing.php?channels=CBS&id=102




    <?php
       
        function db_connect()
        {
          define('DB_HOST', 'localhost');
          define('DB_USER', 'myusername');
          define('DB_PASSWORD', 'mypassword');
          define('DB_DATABASE', 'mydbname');
       
          $errmsg_arr = array();
          $errflag = false;
          $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
       
          if(!$link) 
          {
            die('Failed to connect to server: ' . mysql_error());
          }
       
          $db = mysql_select_db(DB_DATABASE);
          if(!$db) 
          {
            die("Unable to select database");
          }
        }
        db_connect();
       
          function clean($var)
          {
            return mysql_real_escape_string(strip_tags($var));
          } 
          $channels = clean($_GET['channels']);
          $id = clean($_GET['id']);
       
          if($errflag) 
          {
            $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            echo implode('<br />',$errmsg_arr);
          }
          else 
          {
            $insert = array();
       
            if(isset($_GET['channels'])) 
            {
              $insert[] = 'channels = \'' . clean($_GET['channels']) .'\'';
            }
            if(isset($_GET['id'])) 
            {
              $insert[] = 'id = \'' . clean($_GET['id']) . '\'';
            }
       
            if(!$channels && ! $id) 
            {
              $qrytable1="SELECT id, channels, links, streams FROM tvguide";
              $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
             
             
              while ($row = mysql_fetch_array($result1))
              {
                // fake some example data. the actual data would be retrieved from a database query
                $data[] = array('channel_id'=>$row['channels'],
                'display_name'=>$row['channels'],
                'program_id'=>123,'start'=>'s1','stop'=>'e1',
                'title'=>'program title',
                 'sub_title'=>'sub title',
                 'description'=>'program description1',
                 'category'=>'some category');
       
       
       
                // build the xml    
                $xml = '<?xml version="1.0" encoding="UTF-8" ?>
        <tv generator-info-name="www.testbox.elementfx.com/xmltv">';
                $last_channel = null; // used to detect when the channel changes
                foreach($data as $arr)
                {
                    if($last_channel != $arr['channel_id'])
                    {
                        // the channel changed
                        if($last_channel != null)
                        {
                          // not the first channel, close out the previous channel
                          $xml .= "
        </channel> \n";
                         
       
                        }
                        // start a new channel
                        $xml .= "
        <channel id=\"{$arr['channel_id']}\">";
                        $xml .= "
           <display-name>{$arr['display_name']}</display-name>";
                        $last_channel = $arr['channel_id'];
                    }
                    // output the program info under each channel
                    $xml .= "
           <programme channel=\"{$arr['channel_id']}\" start=\"{$arr['start']}\" stop=\"{$arr['stop']}\">";
                    // i don't see a program id in this definition, but it likely needs one
                    $xml .= "
               <title lang=\"en\">{$arr['title']}</title>";
                    $xml .= "
               <sub-title lang=\"en\">{$arr['sub_title']}</sub-title>";
                    $xml .= "
               <desc lang=\"en\">{$arr['description']}</desc>";
                    $xml .= "
               <category lang=\"en\">{$arr['category']}</category>";
                    $xml .= "
           </programme>";
                }
                if($last_channel != null)
                {
                    // close out the previous channel if any
                    $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);
         }
        ?>
    PHP:


    The same things that it goes for each array in the get-listing.php.

    Can you please tell me how I can get the list of strings from each PHP tag `<span id="title1">`, `<span id="title2">` `<span id="title3">` and so on to output for each strings in each xml tag called `<title lang="en">` for each programme using my php source?

    Thanks in advance
     
    mark103, Mar 21, 2014 IP
  2. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    Use
    <?php
    header("Content-type: text/xml");
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    PHP:
    for output in xml format
     
    vOlLvEriNe, Mar 21, 2014 IP
  3. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Dude!!! I never said I want to know how to change the xml source, I SAID that I want to know how I can get access to the get-listing.php script then get access to each of these links:

    http://testbox.elementfx.com/get-listing.php?channels=ABC FAMILY&id=101
    http://testbox.elementfx.com/get-listing.php?channels=CBS&id=102
    http://testbox.elementfx.com/get-listing.php?channels=CNN USA&id=103
    http://testbox.elementfx.com/get-listing.php?channels=ESPN USA&id=105


    And I want to get how I can get each of these programme from php to output them in the xml tag:

    <span id="time1">12:00 PM </span> - <span id="title1">2014 NCAA Basketball Tournament"Dayton vs. Ohio State - LIVE</span><br><br>
        <span id="time2">2:30 PM </span> - <span id="title2">2014 NCAA Basketball Tournament"Western Michigan vs. Syracuse - LIVE</span><br><br>
        <span id="time3">5:00 PM </span> - <span id="title3">Local Programming</span><br><br>
        <span id="time4">6:00 PM </span> - <span id="title4">Local Programming</span><br><br>
        <span id="time5">7:00 PM </span> - <span id="title5">2014 NCAA Basketball Tournament"Wofford vs. Michigan - LIVE</span><br><br>
        <span id="time6">9:30 PM</span> - <span id="title6">2014 NCAA Basketball Tournament"Arizona State vs. Texas - LIVE</span><br><br>
        <span id="time7">12:00 AM </span> - <span id="title7"> 1 Local Programming</span><br><br>
        <span id="time8">12:35 AM </span> - <span id="title8">Late Show With David LettermanTV-PG  </span><br><br>
        <span id="time9">1:37 AM </span> - <span id=title9>The Late Late Show With Craig FergusonTV-14  </span><br><br>
    Code (markup):
    You did not read my post carefully, please read it again and come back to me if you get what I'm talking about?
     
    mark103, Mar 21, 2014 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    I would suggest using DOMDocument for this (If I'm understanding your question properly)... though that XML output is buggy broken gibberish...

    I think I'm really not following your question -- are you working from your own XML output or someone else's you're trying to turn into a page? I mean, if you have access to the database (which your code in the first post makes it look like you do) why aren't you calling that on your page and outputting it as markup instead of that broken mess of invalid XML?

    Could you explain your data sources and what you are trying to do a bit better? If I'm reading this properly, you're going about it all wrong and getting XML involved for no good reason.

    Wait... that CBS source... are you trying to turn that garbage idiot halfwit markup of theirs into XML?

    Yeah, not sure I get the question.
     
    deathshadow, Mar 22, 2014 IP
  5. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Well, what I'm trying to do is to open the url of get-listing.php to get the url in each array to retrieve the data and output it using with "$xml .= "<programme channel=\"{$arr['channel_id']}\" start=\"{$arr['start']}\" stop=\"{$arr['stop']}\">";.

    Can you tell me how i can do that?
     
    mark103, Mar 22, 2014 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #6
    get-listing.php doesn't output the values you are asking for in it's malformed/incomplete XML... or are you saying that you want get-listing.php to take data from somewhere else and output it that way?

    I guess I'm just not following your broken Engrish. I can't figure out what you are actually asking; either that or you are asking for information that doesn't exist in what you are trying to call.
     
    deathshadow, Mar 22, 2014 IP
  7. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #7
    I know that, but it will get the list of channels information from the database.

    I want to use get-listing.php to take data from somewhere else and output it in the xml.

    Take a look at this:

    CBS programme info:

    <span id="time1">12:00 PM </span> - <span id="title1">2014 NCAA Basketball Tournament"Dayton vs. Ohio State - LIVE</span><br><br>
    <span id="time2">2:30 PM </span> - <span id="title2">2014 NCAA Basketball Tournament"Western Michigan vs. Syracuse - LIVE</span><br><br>
    <span id="time3">5:00 PM </span> - <span id="title3">Local Programming</span><br><br>
    <span id="time4">6:00 PM </span> - <span id="title4">Local Programming</span><br><br>
    <span id="time5">7:00 PM </span> - <span id="title5">2014 NCAA Basketball Tournament"Wofford vs. Michigan - LIVE</span><br><br>
    <span id="time6">9:30 PM</span> - <span id="title6">2014 NCAA Basketball Tournament"Arizona State vs. Texas - LIVE</span><br><br>
    <span id="time7">12:00 AM </span> - <span id="title7"> 1 Local Programming</span><br><br>
    <span id="time8">12:35 AM </span> - <span id="title8">Late Show With David LettermanTV-PG  </span><br><br>
    <span id="time9">1:37 AM </span> - <span id=title9>The Late Late Show With Craig FergusonTV-14  </span><br><br>
    Code (markup):

    The xml output would be looks like this:

    <?xml version="1.0" encoding="UTF-8" ?>
    <tv generator-info-name="www.testbox.elementfx.com/xmltv">
    <channel id="CBS">
       <display-name>CBS</display-name>
       <programme channel="CBS" start="s1" stop="e1">
           <title lang="en">2014 NCAA Basketball Tournament"Dayton vs. Ohio State - LIVE</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
       <programme channel="CBS" start="s2" stop="e2">
           <title lang="en">2014 NCAA Basketball Tournament"Western Michigan vs. Syracuse - LIVE</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
       <programme channel="CBS" start="s3" stop="e3">
           <title lang="en">Local Programming</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
       <programme channel="CBS" start="s4" stop="e4">
           <title lang="en">Local Programming</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
    </channel>
    
    <channel id="CNN USA">
       <display-name>CNN USA</display-name>
       <programme channel="CNN USA" start="s1" stop="e1">
           <title lang="en">Wolf</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
       <programme channel="CNN USA" start="s2" stop="e2">
           <title lang="en">CNN Newsroom</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
       <programme channel="CNN USA" start="s3" stop="e3">
           <title lang="en">The Lead With Jake Tapper</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
       <programme channel="CNN USA" start="s4" stop="e4">
           <title lang="en">The Situation Room</title>
           <sub-title lang="en">sub title</sub-title>
           <desc lang="en">program description1</desc>
           <category lang="en">some category</category>
       </programme>
    </channel>
    </tv>
    Code (markup):

    At the moment, my xml output are showing like this:

    <tv generator-info-name="www.testbox.elementfx.com/xmltv">
    <channel id="ABC FAMILY">
    <display-name>ABC FAMILY</display-name>
    <programme channel="ABC FAMILY" start="s1" stop="e1">
    <title lang="en">program title</title>
    <sub-title lang="en">sub title</sub-title>
    <desc lang="en">program description1</desc>
    <category lang="en">some category</category>
    </programme>
    </channel>
    <channel id="CBS">
    <display-name>CBS</display-name>
    <programme channel="CBS" start="s1" stop="e1">
    <title lang="en">program title</title>
    <sub-title lang="en">sub title</sub-title>
    <desc lang="en">program description1</desc>
    <category lang="en">some category</category>
    </programme>
    </channel>
    </tv>
    
    Code (markup):
    Now you got it?
     
    mark103, Mar 22, 2014 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    I'm gonna have to not help, what you are saying seems to have nothing to do with the code you are presenting -- I'm either missing something obvious, or what you are asking has nothing to do with the data and/or code presented.

    Are you JUST asking how to parse that span tag mess? As in everything else you've presented for code has jack **** to do with anything? I'm just really not getting what any of this has to do with the rest of it. Seems like a bunch of unrelated stuff just mashed together.
     
    deathshadow, Mar 22, 2014 IP
    ThePHPMaster likes this.
  9. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #9
    Yes I ******** do, please read my post again.
     
    mark103, Mar 22, 2014 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    @deathshadow he's not the brightest, but what he's asking is the following (I think):
    He's got something outputting XML - where that XML is generated beats me, but I'jm thinking it's the PHP-file linked in the beginning. This PHP-file has dummy placeholders for programs etc. What he wants is get this information from the <span>-tags in the links provided in the get-listing.php (ie, in get-listing.php there are lots of links to other pages showing program listings).
    The overall structure seems to me a bit broken - why go via the get-listing.php to get to the other links, for instance, just go directly to those links - and if those links doesn't have any proper structure, just a bunch of spans, I'm not really sure if PHP-functions for iterating through HTML works properly.
     
    PoPSiCLe, Mar 23, 2014 IP