Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-02-2007, 12:24 AM   PM User | #1
harlequin2k5
Regular Coder

 
harlequin2k5's Avatar
 
Join Date: Sep 2005
Location: Tampa, FL
Posts: 631
Thanks: 14
Thanked 0 Times in 0 Posts
harlequin2k5 is an unknown quantity at this point
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>
harlequin2k5 is offline   Reply With Quote
Old 10-02-2007, 01:53 AM   PM User | #2
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,428
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
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
Alex Vincent is offline   Reply With Quote
Old 10-02-2007, 02:10 AM   PM User | #3
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,744
Thanks: 2
Thanked 255 Times in 247 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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.
CFMaBiSmAd is offline   Reply With Quote
Old 10-02-2007, 03:28 AM   PM User | #4
harlequin2k5
Regular Coder

 
harlequin2k5's Avatar
 
Join Date: Sep 2005
Location: Tampa, FL
Posts: 631
Thanks: 14
Thanked 0 Times in 0 Posts
harlequin2k5 is an unknown quantity at this point
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>
harlequin2k5 is offline   Reply With Quote
Old 10-02-2007, 04:12 AM   PM User | #5
harlequin2k5
Regular Coder

 
harlequin2k5's Avatar
 
Join Date: Sep 2005
Location: Tampa, FL
Posts: 631
Thanks: 14
Thanked 0 Times in 0 Posts
harlequin2k5 is an unknown quantity at this point
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..
harlequin2k5 is offline   Reply With Quote
Old 10-02-2007, 04:34 PM   PM User | #6
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,292
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
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
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||

Last edited by _Aerospace_Eng_; 10-02-2007 at 04:47 PM..
_Aerospace_Eng_ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:10 AM.


Advertisement
Log in to turn off these ads.