Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Output arrays from php to xml

    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:


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

    CBS link: http://testbox.elementfx.com/get-lis...els=CBS&id=102




    PHP Code:
    <?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_HOSTDB_USERDB_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);
         }
        
    ?>


    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

  • #2
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    does anyone know how i can do this? anyone?

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You could treat it as a string, and simply explode it and cut it up. Personally I don't like that.
    Where does this first block of code come from, and how does it relate to the second block of code provided? Is it a part of the query there?

    You *may* want to consider using a dom as well. Although this is relatively little and straight forward XML generation, the dom gives the advantage of shifting around items without needing to change individual item structure. It comes at the cost of memory.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You could treat it as a string, and simply explode it and cut it up. Personally I don't like that.
    Where does this first block of code come from, and how does it relate to the second block of code provided? Is it a part of the query there?

    You *may* want to consider using a dom as well. Although this is relatively little and straight forward XML generation, the dom gives the advantage of shifting around items without needing to change individual item structure. It comes at the cost of memory.

    I don't understand what you mean by where does this first block of code come from?

    What I said in my first post that I want to get the list of links for each array in get-listing.php like this:

    http://testbox.elementfx.com/get-lis...p?channels=ABC FAMILY&id=101
    http://testbox.elementfx.com/get-lis...els=CBS&id=102
    http://testbox.elementfx.com/get-lis...p?channels=CNN USA&id=103
    http://testbox.elementfx.com/get-lis...?channels=ESPN USA&id=105
    ..and so on


    I want to connect on each link in my PHP for each array to get the list of programme info to output them in the XML source.

    Here's for e.g:

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

    I want to connect on get-listing.php to get the list of links on each array and I want to connect on each link in the get-listing.php to get the programme info.


    CBS programme info:

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

    CNN programme info:

    Code:
    <span id="time1">1:00 PM </span> - <span id="title1">Wolf</span><br><br>
    <span id="time2">2:00 PM </span> - <span id="title2">CNN Newsroom</span><br><br>
    <span id="time3">4:00 PM </span> - <span id="title3">The Lead With Jake Tapper</span><br><br>
    <span id="time4">5:00 PM </span> - <span id="title4">The Situation Room</span><br><br>
    <span id="time5">6:30 PM </span> - <span id="title5">Crossfire</span><br><br>
    <span id="time6">7:00 PM </span> - <span id="title6">Erin Burnett OutFront</span><br><br>
    <span id="time7">8:00 PM </span> - <span id="title7">Anderson Cooper 360</span><br><br>
    <span id="time8">9:00 PM </span> - <span id="title8">Piers Morgan Live</span><br><br>
    <span id="time9">10:00 PM </span> - <span id="title9">CNN Spotlight</span><br><br>

    I want to get the list of programme info from each tag of <span id="title1, <span id="title2, <span id="title3...etc to allow me to generating for each xml tag <programme channel="CHANNEL NAME" start="s1" stop="e1">, <programme channel="CHANNEL NAME" start="s2" stop="e2"> with each different start and end times then output the programe title in each xml tag called <title lang="en">.

    The output for the XML would be looks like this:

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

    Do you know how i can do that using my PHP?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •