Reply to PHP and XML : Why the number "1" is getting display

Your name:

Reply:


Posted by patrice.fiset@gmail.com on 07/01/07 22:13

Hello,

I have a simple script, basically it looks through the XML file and
when the parser is at the tag 'title', on the function charElement I
display OK, but for some reason, the number 1 is getting display. I
really don't get it here.

Thanks for help and here's the code.

<?
include("includes/connexion.php");
// Global variables for function use.
$GLOBALS['item'] = false;
$GLOBALS['title'] = false;

// function: startElement
// Deals with the starting element
function startElement( $parser, $tagName, $attrs ) {
// By setting global variable of tag name
// I can determine which tag I am currently
// parsing.
switch( $tagName ) {
case 'ITEM':
$GLOBALS['item'] = true;
break;
case 'TITLE':
$GLOBALS['title'] = true;
break;
}
}

function endElement( $parser, $tagName ) {
//$repl = array('é' => '&#233;','è' => '&#232;','ç' =>
'&#231;','ê' => '&#234;','ë' => '&#235;','î' => '&#238;','ï' =>
'&#239;','ô' => '&#244;','ö' => '&#246;','ù' => '&#249;','ö' =>
'&#246;');
// By noticing the closing tag,
// I can print out the data that I want.
if ($GLOBALS['item'] === true)
{
switch( $tagName ) {
case 'TITLE':
//echo "<tr><td class='boldDev'
colspan='2'>".str_replace(array_keys($repl), array_values($repl),
$GLOBALS['titletext'])."</a></td></tr>";
print $GLOBALS['title']."<br>";
$GLOBALS['title'] = false;
$GLOBALS['title'] = "";
break;
}
}

}

// function: charElement
// Deals with the character elements (text)
function charElement( $parser, $text ) {
// Verify the tag that text belongs to.
// I set the global tag name to true
// when I am in that tag.
if ($GLOBALS['item'] === true)
{
if ($GLOBALS['title'] === true)
print "OK";
//print $text;//print htmlspecialchars( trim($text) );//
$GLOBALS['title'] .= htmlspecialchars( trim($text) );
}
}

// Create an xml parser
$xmlParser = xml_parser_create();



// Open connection to RSS XML file for parsing.
$fp = fopen( "http://www.mckaulick.com/feeds/mondernier.xml", "r" )
or die( "Cannot read RSS data file." );


// Set up element handler
xml_set_element_handler( $xmlParser, "startElement", "endElement" );

// Set up character handler
xml_set_character_data_handler( $xmlParser, "charElement" );


// Parse XML data from RSS file.
while( $data = fread( $fp, 4096 ) ) {
xml_parse( $xmlParser, $data, feof( $fp ) );
}


// Close file open handler
fclose( $fp );


// Free xml parser from memory
xml_parser_free( $xmlParser );

?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация