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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Maryland, USA
    Posts
    165
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Using PHP to generate and XML RSS Feed

    Hello,

    I'm using a PHP page to draw information from an SQL database and generate and RSS feed via XML. Lots of acronyms huh?

    Anyway, I've pretty much finished the whole thing... it's just not working. I'm not sure why.

    Essentially, when you view the xml page, none of the items show up. But when viewing the source, everything looks right. The xml seems to be generated correctly, so I'm not sure what's causing the issue.

    Here's the php
    PHP Code:
    <?php 
    include "phpdb/dbaccess.php";

    header'Content-Type: text/xml' );
    echo 
    "<?xml version='1.0' ?>
    <?xml-stylesheet href='rss.xsl' type='text/xsl' media='screen' ?>
    <rss version='2.0'>
    <channel>
    <title>Turning the Tide</title>
    <language>en-us</language>
    <link>http://www.maggiepascal.com/</link>
    <description>Turning the Tide</description>
    <webMaster>matt@knowideaproductions.com</webMaster>
    "
    ;

    $timeConvert = array (
        
    "01:00:00" => "1am""02:00:00" => "2am""03:00:00" => "3am""04:00:00" => "4am""05:00:00" => "5am""06:00:00" => "6am""07:00:00" => "7am",    "08:00:00" => "8am""09:00:00" => "9am""10:00:00" => "10am""11:00:00" => "11am""12:00:00" => "12pm""13:00:00" => "1pm""14:00:00" => "2pm""15:00:00" => "3pm""16:00:00" => "4pm""17:00:00" => "5pm""18:00:00" => "6pm""19:00:00" => "7pm""20:00:00" => "8pm""21:00:00" => "9pm""22:00:00" => "10pm""23:00:00" => "11pm""24:00:00" => "12am"    
        
    );

    $query "SELECT * FROM tblShow, tblGuest WHERE tblShow.fk_tblGuest = tblGuest.pk_tblGuest ORDER BY showdate DESC,starttime DESC";
    $result mysql_query($query) or die("Error, the server encountered an error:".mysql_error());
    while (
    $r mysql_fetch_assoc($result)){
            
        
    $showDateArray explode("-",$r['showdate']);
        
    $showDateDisplaydate('M d, Y'mktime(0,0,0,$showDateArray[1],$showDateArray[2],$showDateArray[0]));
            
        
    $firstname preg_replace('/(\\\")/',"&quot;"$r['firstname']);
        
    $firstname preg_replace("/(\\\')/","&rsquo;"$firstname);
        
    $lastname preg_replace('/(\\\")/',"&quot;"$r['lastname']);
        
    $lastname preg_replace("/(\\\')/","&rsquo;"$lastname);
        
    $topic preg_replace('/(\\\")/',"&quot;"$r['topic']);
        
    $topic preg_replace("/(\\\')/","&rsquo;"$topic);

        if (
    $r['prefix'] == NULL && $r['firstname'] == NULL && $r['lastname'] == NULL){
            
    $guestName "No Guest";
        }
        else{
            
    $guestName $r['prefix']." ".$r['firstname']." ".$r['lastname'];
        }
        
            
        echo
    "
        <item>
        <title>$guestName</title>
        <description>$topic</description>"
    ;
        
        if (
    $showInfo['audio'] != NULL){
                
    $audioSize filesize("http://www.maggiepascal.com/{$r['audio']}");
            echo 
    "\n <link>http://www.maggiepascal.com/{$r['audio']}</link>";
        
    // <enclosure url='http://www.maggiepascal.com/{$r['audio']}' length='$audioSize' type='audio/mpeg' />
        
    }
        if (
    $showInfo['video'] != NULL){
                
    $videoSize filesize("http://www.maggiepascal.com/{$r['video2']}");
            echo 
    "\n <link>http://www.maggiepascal.com/watch?showid={$r['pk_tblShow']}</link>";
        
    // <enclosure url='http://www.maggiepascal.com/watch?showid={$r['pk_tblShow']}' length='$videoSize' type='video/swf' />
        
    }
        if (
    $showInfo['video2'] != NULL){
                
    $video2Size filesize("http://www.maggiepascal.com/{$r['video2']}");
            echo 
    "\n <link>http://www.maggiepascal.com/watch?showid={$r['pk_tblShow']}&segment=2</link>";
        }
        if (
    $showInfo['video3'] != NULL){
            
    $video4Size filesize("http://www.maggiepascal.com/{$r['video4']}");
            echo 
    "\n <link>http://www.maggiepascal.com/watch?showid={$r['pk_tblShow']}&segment=3</link>";
        }
        if (
    $showInfo['video4'] != NULL){
            
    $video3Size filesize("http://www.maggiepascal.com/{$r['video3']}");
            echo 
    "\n <link>http://www.maggiepascal.com/watch?showid={$r['pk_tblShow']}&segment=4</link>";
        }
        
        echo 
    "
        <pubDate>$r{$showdate}</pubDate>
        <time>{$r['starttime']}</time>
        </item>
        "
    ;
    }

    echo 
    "
    </channel>
    </rss>
    "
    ;
    ?>
    You can visit http://www.maggiepascal.com/podcast.php to see the page and view its source.

    If anyone has any ideas, I'd really appreciate the help. I expect that the problem must be something subtle...

    I should also add that I'm trying to add up to 4 video links to each item. This is because the video's are often split into 3-4 segments. I'm not sure that I'm going about it the right way.
    Last edited by madmatter23; 03-08-2008 at 01:38 AM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I think your problem is in the top portion of the script.
    I took a snippet of code from another XML script.

    Try this replacement for the first part of your script ...

    PHP Code:
    <?php 
    include "phpdb/dbaccess.php";

    // Begin feed
    header ("Content-Type: text/xml; charset=ISO-8859-1");
    echo 
    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
    ?>
    <rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <channel>
    <title>Turning the Tide</title>
    <language>en-us</language>
    <link>http://www.maggiepascal.com/</link>
    <description>Turning the Tide</description>
    <webMaster>matt@knowideaproductions.com</webMaster>

    <?php
    $timeConvert 
    = array (
        
    "01:00:00" => "1am""02:00:00" => "2am""03:00:00" => "3am""04:00:00" => "4am""05:00:00" => "5am""06:00:00" => "6am""07:00:00" => "7am",    "08:00:00" => "8am""09:00:00" => "9am""10:00:00" => "10am""11:00:00" => "11am""12:00:00" => "12pm""13:00:00" => "1pm""14:00:00" => "2pm""15:00:00" => "3pm""16:00:00" => "4pm""17:00:00" => "5pm""18:00:00" => "6pm""19:00:00" => "7pm""20:00:00" => "8pm""21:00:00" => "9pm""22:00:00" => "10pm""23:00:00" => "11pm""24:00:00" => "12am"    
        
    );

    the rest of your script
    .
    .
    .
    Last edited by mlseim; 03-08-2008 at 05:00 AM.

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    Maryland, USA
    Posts
    165
    Thanks
    12
    Thanked 0 Times in 0 Posts
    No luck with the new header, thanks for the advice though. I have noticed that the feed actually does work in safari, just not in firefox... It's tough to know where to start with the problem since there is no error message. Any other ideas?

    Thanks!

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    dumb it down ...

    Try making a simple XML file without any database stuff.
    Just use a few simple tags and some "jibberish" text for testing.

    See if you can make a simple XML file work before including
    all of your database information. That might trigger some ideas.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    I hope I don't missunderstand your problem.
    You can't just echo an xml file becouse of special chars, try this:

    PHP Code:
    echo "<pre>".htmlspecialchar($xml)."</pre>"
    here I asume you have in $xml the content of your xml.

    best regards

  • #6
    Regular Coder
    Join Date
    Jun 2007
    Location
    Maryland, USA
    Posts
    165
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Thanks for the advice, I think that I'm a lot closer to having it work.

    I changed the header tags, ran most of the xml through htmlspecialchars(), and now I'm just having trouble with the filesize() command.
    Last edited by Inigoesdr; 03-09-2008 at 06:22 PM. Reason: Double-post


  •  

    Posting Permissions

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