Php reading rrs was previously written into a php reading shou Forum rrs for your reference due to the needs of the school Forum.
// The following is the definition function to extract data:
// Processing start tag attributes refer
// $ Attrs is a multi-dimensional array. The key value is the attribute name and the value is the value of this attribute.
Function startElement ($ parser, $ element_name, $ attrs ){
Global $ temp, $ current_tag;
$ Current_tag = $ element_name;
Switch ($ element_name ){
Case 'item ':
Echo '';
Break;
Default:
Break;
}
}
// $ Current_tag indicates the tag being processed, which will be used in the characterData function.
Function endElement ($ parser, $ element_name, $ attrs ){
Global $ temp, $ current_tag;
Switch ($ element_name ){
Case 'item ':
Return_page ($ temp );
$ Temp = '';
Break;
Default:
Break;
}
}
// Transmits data between elements to this function.
// For exampleTitle Here, $ Data is equal to 'title Here'
Function characterData ($ parser, $ data ){
Global $ current_tag, $ temp, $ catID;
Switch ($ current_tag ){
Case 'Title ':
$ Temp ['title'] = $ data;
$ Current_tag = '';
Break;
Case 'link ':
$ Temp ['URL'] = $ data;
$ Current_tag = '';
Break;
Case 'author ':
$ Temp ['author'] = $ data;
$ Current_tag = '';
Case 'description ':
$ Temp ['description'] = $ data;
$ Current_tag = '';
Default:
Break;
}
}
?>
Function return_page (){
Global $ temp;
Echo 'O'. $ temp ['title'].'
';
}
// The analysis content, that is, the unknown rrs, which can be a network location or a file
$ Xml_file = 'http://club.sohu.com/list-70th-0-0.xml ';
// Define the character set, which is the UTF-8 by default
// $ Type = 'utf-8 ';
// Create a parser
$ Xml_parser = xml_parser_create ();
// Set resolution options
// Xml_parser_set_option ($ xml_parser, XML_OPTION_CASE_FOLDING, true );
// Xml_parser_set_option ($ xml_parser, XML_OPTION_TARGET_ENCODING, 'utf-8 ');
// Tell PHP what function to call when discovering an element
// These functions also process Element attributes.
Xml_set_element_handler ($ xml_parser, 'startelement ', 'enabledement ');
// Tell PHP what function is called for character data
Xml_set_character_data_handler ($ xml_parser, 'characterdata ');
If (! ($ Fp = fopen ($ xml_file, 'r '))){
Die ("unable to obtain data temporarily due to network problems, please refresh and try again later ");
}
// Parse the entire file through loops
While ($ data = fread ($ fp, 1024 ))
{
Xml_parse ($ xml_parser, $ data, feof ($ fp ));
}
Fclose ($ fp );
Xml_parser_free ($ xml_parser );
?>
You can also add a javascript script to pre-load the webpage.
<Script language = "JavaScript">
<Script language = "JavaScript">
<Style type = "text/css">
<P id = "ld" style = "position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; background-color: # ffffFF; z-index: 1000; ">
<Br>
<Br>
<Table align = "center" width = "50%">
<Tr>
<Td align = "center"> <font color = # 0000ff> <B> SOHU forum <Br>
<Br>
<Font color = "# 0000ff"> loading... please wait... ...
<Table width = "50%" align = "center" border = "0" cellspacing = "1" cellpadding = "0"