Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello everyone,
I have been trying to write a simple code that reads and RSS feed from yahoo! website and parses it and writes the contents on a new page. However, I have this problem that when I tried to use a separate function to format the output HTML, everything got distorted. The code below works, but if you try to use the other option (the function) and uncomment the commented lines and use them, everything goes wrong. Please tell me what is wrong with my code? Thanks
<?php
$open_stack = array();
$parser = xml_parser_create();xml_set_element_handler ( $parser, "start_handler", "end_handler" );
xml_set_character_data_handler ( $parser, "character_handler" );
xml_parser_set_option ( $parser, XML_OPTION_CASE_FOLDING, 0 );print "<html><title>ARNIT NEWS CENTRE</head><body>\n\n";
xml_parse ($parser, file_get_contents ( "http://rss.news.yahoo.com/rss/tech" ) )
or die ( format_error ( $parser ) );xml_parser_free ( $parser );
print "</body></html>";
function start_handler ( $p, $name, $atts ) {
global $open_stack;
$open_stack[] = array($name, "");
}function character_handler ( $p, $txt ) {
global $open_stack;
$cur_index = count($open_stack)-1;$open_stack [$cur_index][1] =
$open_stack[$cur_index][1].$txt;}
function end_handler ( $p, $name ) {
global $open_stack;
$el = array_pop ( $open_stack );switch ( $name )
{
case 'title':
//$title = $el[1];
print "$el[1]";
break;case 'description':
//$description = $el[1];print "$d$el[1]
";
break;case 'link':
//$links = $el[1];
print "
Read more\n\n\n
";
break;}
//format_html ( $title, $details, $links );
}
function format_html ( $t, $d, $l ) {print "$t";
print "$d\n
";
print "
Read more\n\n\n
";
}
function format_error ( $p ) {$code = xml_get_error_code ( $p );
$str = xml_error_string ( $code );
$line = xml_get_current_line_number ( $p );
return "XML ERROR ($code): $str at line $line";
}
?>

![]() |
sql server
|
How should I proceed with...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |