april2008 Posted March 26, 2009 Share Posted March 26, 2009 Having error for my code Parse error: parse error, unexpected T_AS in C:\Apache2.2\htdocs\rssread.php on line 4 this is the code i have <?php $rssFeeds = array ('phpbuilder.rss'); // for now we'll just have the one file, but this can later be expanded //Loop through the array (just one element for now) and read the feedforeach ($rssFeeds as $feed) { readFeeds($feed);} // The function to be called when a start element is read. For now we'll // just echo some outputfunction startElement($xp,$name,$attributes) { echo "Start $name <br>";} function endElement($xp,$name) { echo "End: $name<br>";} function readFeeds($feed) { $fh = fopen($feed,'r'); // open file for reading $xp = xml_parser_create(); // Create an XML parser resource xml_set_element_handler($xp, "startElement", "endElement"); // defines which functions to call when element started/ended while ($data = fread($fh, 4096)) { if (!xml_parse($xp,$data)) { return 'Error in the feed'; } }}?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 26, 2009 Share Posted March 26, 2009 You probably need foreach before ($rssFeeds as $feed) If you look carefully you'll see it got into a comment one line above. Quote Link to comment Share on other sites More sharing options...
POG1 Posted March 26, 2009 Share Posted March 26, 2009 ($rssFeeds as $feed) { readFeeds($feed);} That line is doing nothing.. Quote Link to comment Share on other sites More sharing options...
april2008 Posted March 26, 2009 Author Share Posted March 26, 2009 ok. i changed to the code below <?php $rssFeeds = array ('phpbuilder.rss'); // for now we'll just have the one file, but this can later be expanded //Loop through the array (just one element for now) and read the feedforeach foreach ($rssFeeds as $feed) { readFeeds($feed); } // The function to be called when a start element is read. For now we'll // just echo some outputfunction function startElement($xp,$name,$attributes) { echo "Start $name <br>";} function endElement($xp,$name) { echo "End: $name<br>";} function characterDataHandler($xp,$data) { echo "Data: $data "; } function readFeeds($feed) { $fh = fopen($feed,'r'); // open file for reading $xp = xml_parser_create(); // Create an XML parser resource xml_set_element_handler($xp, "startElement", "endElement"); // defines which functions to call when element started/ended while ($data = fread($fh, 4096)) { if (!xml_parse($xp,$data)) { return 'Error in the feed'; } }}?> but how come it display a blank page? Quote Link to comment Share on other sites More sharing options...
POG1 Posted March 26, 2009 Share Posted March 26, 2009 You will need to change the error reporting to E_ALL Quote Link to comment Share on other sites More sharing options...
april2008 Posted March 26, 2009 Author Share Posted March 26, 2009 which part of error reporting? Quote Link to comment Share on other sites More sharing options...
POG1 Posted March 26, 2009 Share Posted March 26, 2009 ini_set() or try looking in the error log. Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 26, 2009 Share Posted March 26, 2009 Check 'PHP Debugging: A Beginner's guide ' link in my signature. Besides, none of your code actually echoes anything, so what do you expect? Ok I see it now Quote Link to comment Share on other sites More sharing options...
april2008 Posted March 27, 2009 Author Share Posted March 27, 2009 OK. i already turn on the ini_set('display_errors','On'); but it still blank phpbuilder.rss <? xml version="1.0" ?> <rss version="0.91"> <channel> <pubDate>Thu, 29 Sep 2005 15:16:13 GMT</pubDate> <description>Newest Articles and How-To's on PHPBuilder.com</description> <link>http://phpbuilder.com</link> <title>PHPBuilder.com New Articles</title> <webMaster>staff@phpbuilder.com</webMaster> <language>en-us</language> <item> <title>In Case You Missed It...The Week of September 26, 2005</title> <link>http://www.phpbuilder.com/columns/weeklyroundup20050926.php3</link> <description>This week Elizabeth brings us news of an upcoming free webcast called Design Patterns in PHP, the schedule for the Fall Zend conference, security alerts for Moveable Type and phpBB, the release of Zend Platform 2, XAMPP for Linux, the latest PEAR/PECL releases and much more! </description> </item> <item> <title>In Case You Missed It...The Week of September 19, 2005</title> <link>http://www.phpbuilder.com/columns/weeklyroundup20050919.php3</link> <description>This week Elizabeth brings us news of the release of PEAR 1.4, Zend Studio 5 Beta, a security vulnerability with PHP-Nuke, the release of a SimpleTest plugin for PHPEclipse, a patch for phpMyAdmin, the latest PEAR/PECL releases and much, much more!</description> </item> </channel> </rss> rssread.php <?php ini_set('display_errors','On'); ?> <?php $rssFeeds = array ('phpbuilder.rss'); //Loop through the array, reading the feeds one by one foreach ($rssFeeds as $feed) { readFeeds($feed); } function startElement($xp,$name,$attributes) { echo "Start $name"; } function endElement($xp,$name) { echo "End: $name"; } function characterDataHandler($xp,$data) { echo "Data: $data "; } function readFeeds($feed) { $fh = fopen($feed,'r'); // open file for reading $xp = xml_parser_create(); // Create an XML parser resource xml_set_element_handler($xp, "startElement", "endElement"); // defines which functions to call when element started/ended xml_set_character_data_handler($xp, "characterDataHandler"); while ($data = fread($fh, 4096)) { if (!xml_parse($xp,$data)) { return 'Error in the feed'; } } } ?> ??? Quote Link to comment Share on other sites More sharing options...
Penelopa Posted April 20, 2010 Share Posted April 20, 2010 Hello, may be this scheme can help you: <?php //Initialize the XML parser $parser=xml_parser_create(); /*Function to use at the start of an element*/ function start($parser,$element_name,$element_attrs) { switch($element_name) { case "NOTE": echo "-- Note --<br />"; break; case "TO": echo "To: "; break; case "FROM": echo "From: "; break; case "HEADING": echo "Heading: "; break; case "BODY": echo "Message: "; } } //Function to use at the end of an element function stop($parser,$element_name) { echo "<br/>"; } //Function to use when finding character data function char($parser,$data) { echo $data; } //Specify element handler xml_set_element_handler($parser,"start","stop"); //Specify data handler xml_set_character_data_handler($parser,"char"); //Open XML file $fp=fopen("test.xml","r"); //Read data while ($data=fread($fp,4096)) { xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } //Free the XML parser xml_parser_free($parser); ?> For giving of this example I used this resource http://phpforms.net/tutorial/php-xml/xml-expat-parser.html Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 20, 2010 Share Posted April 20, 2010 It's unlikely that OP still has this problem after more than one YEAR. Anyway, welcome to the PHPFreaks, please remember about using code tags, when pasting any code. Please familiarise yourself with Rules & TOS Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.