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
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    how PHP print out RSS?

    How PHP able to print out a rss html page like this:
    feed://feeds.wired.com/wired/index

    this is my code below , asking php to print out a xml data , how can it into a rss like the above one?

    PHP Code:
    echo "<?xml version="1.0\"?>\n";
    echo 
    "<data>\n";

    while(
    $line mysql_fetch_assoc($results)) {
    echo 
    "<sndata sn=\"" $line["serial_no"]."\">\n";
    echo 
    "<companyname>" $line["company_name"] . "</companyname>\n";
    echo 
    "<numberid>" $line["number_id"] . "</numberid>\n";

    }
    Last edited by terter2000; 01-13-2010 at 03:22 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Take a look at http://www.supadupawebdesign.co.uk/t...in-PHPMySQL-11 (of course, it gets data from mysql DB, but you may easily modify it)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    terter2000 (01-13-2010)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Firstly use single quotes to write your xml data structure and also sprintf your values into a template for the looping process. It makes your code so much cleaner to read. Example
    PHP Code:
    <?php
    $output 
    '<?xml version="1.0"?>
    <data>'
    ;

    $datatemplate '
        <sndata sn="%s">
            <companyname>%s</companyname>
            <numberid>%s</numberid>
        </sndata>'
    ;

    while(
    $line mysql_fetch_assoc($results)) {
        
    $output .= sprintf($datatemplate$line['serial_no'], $line['company_name'], $line['number_id']);
    }

    $output .= '
    </data>'
    ;

    header('Content-Type: text/xml');
    echo 
    $output;
    Note that I also used the text/xml header to signify to your browser that this is an xml document
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    terter2000 (01-13-2010)

  • #4
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    hey thanks experts , it helps +rep and everything !


  •  

    Posting Permissions

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