php and xml (rss)

Discussion in 'PHP' started by promotingspace.net, Nov 29, 2010.

  1. #1
    Hi
    I have wrote a code to generate rss feed by a php script
    It works fine on localhost, but when uploaded to the server, it sends this error:
    Parse error: syntax error, unexpected T_STRING in /path_to_directory/rss_feed.php on line 12
    As you see line 12 is:
    
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    Code (markup):
    This is the script itself:
    <?php
    session_start(); 
     require("dbconnect.php"); 
     if(!isset($_SESSION['usertype']))
       { 
       	header("Location: login.php");
    	}
    else
    	{
    header("Content-Type: application/xml; charset=ISO-8859-1"); 
    ?>
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <rss version="2.0">
    
    <channel>
      <title>page title</title>
      <link>page link</link>
    <?php
    
    $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 ");
    while($row=mysql_fetch_array($result)){
    
    //there are some more code here
    
    $item="<item>
        <title>$title</title>
        <link>$link</link>
        <description>$desc</description>
      </item>";
    
    echo $item;
    
    }
    
    	}
    ?>
    </channel>
    </rss>
    PHP:
    Thank you very much for your help
     
    promotingspace.net, Nov 29, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    It is because the symbols "<?" is told the server that php script start. Change the script to:

    
    <?php
    session_start();
     require("dbconnect.php");
     if(!isset($_SESSION['usertype']))
       {
        header("Location: login.php");
        }
    else
        {
    header("Content-Type: application/xml; charset=ISO-8859-1");
    
    echo('<?xml version="1.0" encoding="ISO-8859-1" ?>
    <rss version="2.0">
    
    <channel>
      <title>page title</title>
      <link>page link</link>');
    
    $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 ");
    while($row=mysql_fetch_array($result)){
    
    //there are some more code here
    
    $item="<item>
        <title>$title</title>
        <link>$link</link>
        <description>$desc</description>
      </item>";
    
    echo $item;
    
    }
    
        }
    ?>
    </channel>
    </rss>
    
    PHP:
     
    s_ruben, Nov 29, 2010 IP
  3. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    <?php
    session_start();
     require("dbconnect.php");
     if(!isset($_SESSION['usertype'])):
        header("Location: login.php");
     else:
      
    header("Content-Type: application/xml; charset=ISO-8859-1");
    ?>
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <rss version="2.0">
    <channel>
      <title>page title</title>
      <link>page link</link>
       <items>
    <?php
    $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 ");
    while($row=mysql_fetch_array($result)){
    
    //there are some more code here
    
    $item="<item>
        <title>$title</title>
        <link>$link</link>
        <description>$desc</description>
      </item>";
    
    echo $item;
    	} // End While
    ?> 
    </items>
    </channel>
    </rss>
    
    <?php endif;?>
    PHP:
     
    guardian999, Nov 29, 2010 IP
  4. Nahid

    Nahid Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?php
    session_start(); 
     require("dbconnect.php"); 
     if(!isset($_SESSION['usertype']))
       { 
        header("Location: login.php");
        }
    else
        {
    header("Content-Type: application/xml; charset=ISO-8859-1"); 
    
    echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';
    
    ?>
    <rss version="2.0">
    
    <channel>
      <title>page title</title>
      <link>page link</link>
    <?php
    
    $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 ");
    while($row=mysql_fetch_array($result)){
    
    //there are some more code here
    
    $item="<item>
        <title>$title</title>
        <link>$link</link>
        <description>$desc</description>
      </item>";
    
    echo $item;
    
    }
    
        }
    ?>
    </channel>
    </rss>
    
    
    Code (php):
     
    Nahid, Dec 6, 2010 IP