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 harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Parse error: parse error, unexpected T_STRING

    I went through a few different tutorials for creating a dynamic rss feed and I found this one by tiffany brown to be most helpful

    unfortunately I'm doing something wrong and not being well-versed with xml at all I'm not sure what to do next

    I get that nasty lil parse error and considering that the first line is
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    I didn't know what to do first

    this is my feed - there are currently 3 articles that it can display:
    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0">
      <channel>
        <title>Shopping Center Advisor</title>
        <link>http://www.shoppingcenter-advisor.com/test</link>
        <description>The definitive source for Shopping Center Information</description>
        <language>en-us</language>
        <managingEditor>webmaster@shoppingcenter-advisor.com</managingEditor>
        <webMaster>webmaster@shoppingcenter-advisor.com</webMaster>
        <copyright>2007 Ronald L. McDonald</copyright>
        <?
    include('functionlist.php');
    $conn=doconnect();
            
    $query "SELECT id,title,content,DATE_FORMAT(added,'%c/%e/%y') as added FROM articles order by added desc limit 5";
            
    $result mysql_query($query) or die("Error: " mysql_error());
            while (
    $row mysql_fetch_array($result))    
            {
    ?>
        <item>
          <title> <?=htmlentities(strip_tags($row['title'])); ?></title>
            <description> <?=htmlentities(strip_tags($row['content'],'ENT_QUOTES'));?></description>
            <link>http://www.shoppingcenter-advisor.com/test/articles.php?p=<?=$row['id'];?></link>
        </item>
        <? ?>  
      </channel>
    </rss>

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,453
    Thanks
    1
    Thanked 21 Times in 19 Posts
    I'll bet five pennies that it's because PHP is trying to interpret the XML declaration. <?php ?> is what PHP should use to start reading text, but <?foo ?>, <?bar ?>, <?baz ?>, <?etc ?>, are all often caught by PHP as well. So's <?xml ?> and <?xml-stylesheet ?>. It's a pet peeve of mine.

    This is because of PHP's default of short open tags. See http://www.php.net/manual/en/ini.core.php for details. You probably need to turn them off in your Apache configuration (perhaps by .htaccess).
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    The short open tag parsing is not smart enough to know that -
    <?any_thing_else_here (that is not "php", "=", white-space, or a newline) is NOT an opening php tag.

    Either put the <?xml... tag in a string and echo it, escape the ? (I think <\?xml... will work), or turn off short open tags.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts
    it still took a bit of work and it's not validating - but the feed is finally working!!!

    this is what I wound up with...
    Code:
    <?php echo '<?xml version="1.0" encoding="iso-8859-1"?>'; ?>
    <rss version="2.0">
      <channel>
        <title>Shopping Center Advisor</title>
        <link>http://www.shoppingcenter-advisor.com/test</link>
        <description>The definitive source for Shopping Center Information</description>
        <language>en-us</language>
        <managingEditor>webmaster@shoppingcenter-advisor.com</managingEditor>
        <webMaster>webmaster@shoppingcenter-advisor.com</webMaster>
        <copyright>2007 Ronald L. McDonald</copyright>
        <?php
    include('functionlist.php');
    $conn=doconnect();
    		$query = "SELECT id,title,content,DATE_FORMAT(added,'%c/%e/%y') as added FROM articles order by added desc limit 5";
    		$result = mysql_query($query) or die("Error: " . mysql_error());
    		while ($row = mysql_fetch_array($result))	
    		{
    ?>
        <item>
          <title> <?=htmlentities(strip_tags($row['title'])); ?></title>
            <description> <?=htmlentities(strip_tags($row['content'],'ENT_QUOTES'));?></description>
            <link>http://www.shoppingcenter-advisor.com/test/feed.php?p=<?=$row['id'];?></link>
        </item>
        <? } ?>  
      </channel>
    </rss>

  • #5
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts

    oops - not working in opera

    is that because it didn't validate? is it one of those errors causing it to not work?

    and unfortunately I also need to test in aol and it's not working there either...
    Last edited by harlequin2k5; 10-02-2007 at 04:14 AM.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Its not validating because its not parsing the php. You need to change it from .xml to .php and you also need to pass the right headers. I've taken out the while loop but you should get the idea. You also need a <guid></guid> (click me) on the <item></item>.
    PHP Code:
    <?php 
    header
    ("Content-Type: application/xml");
    echo 
    '<?xml version="1.0" encoding="UTF-8"?>'
    ?>
    <rss version="2.0">
    <channel>
    <title>Shopping Center Advisor</title>
    <link>http://www.shoppingcenter-advisor.com/test
    </link>
    <description>The definitive source for Shopping Center Information</description>
    <language>en-us</language>
    <managingEditor>webmaster@shoppingcenter-advisor.com</managingEditor>
    <webMaster>webmaster@shoppingcenter-advisor.com</webMaster>
    <copyright>2007 Ronald L. McDonald</copyright>
    <item>
        <title>Test</title>
        <description>This is a description</description>
        <guid>http://google.com</guid>
        <link>
        http://google.com
        </link>
    </item>
    </channel>
    </rss>
    http://feedvalidator.org/check.cgi?u...com%2Ftest.php
    Last edited by _Aerospace_Eng_; 10-02-2007 at 04:47 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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