Jump to content

unexpected T_AS


april2008

Recommended Posts

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';    }  }}?>

 

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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';

    }

  }

}

?>

 

???

Link to comment
Share on other sites

  • 1 year later...

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.