Jump to content

XML PARSING Error (IN PHP4)


tarun

Recommended Posts

<?php
if (!($fp=@fopen("topics.xml", "r"))) {
echo ("Forum Could Failed To Load");
return;
}
$usercount1=0;
$usercount2=0;
$usercount3=0;
$userdata=array();
$state='';

function startElementHandler ($parser,$name,$attrib){
global $usercount;
global $userdata;
global $state;

switch ($name) {
case $name=="IMPORTANT" : {
$userdata[$usercount]["type_i"] = $attrib["TYPE"];
$userdata[$usercount]["who_i"] = $attrib["WHO"];
$userdata[$usercount]["id_i"] = $attrib["ID"];
$userdata[$usercount]["date_i"] = $attrib["DATE"];
$userdata[$usercount]["time_i"] = $attrib["TIME"];
$userdata[$usercount]["title_i"] = $attrib["TITLE"];
$userdata[$usercount]["posts_i"] = $attrib["POSTS"];
break;
}
case $name=="STICKY" : {
$userdata[$usercount]["type_s"] = $attrib["TYPE"];
$userdata[$usercount]["who_s"] = $attrib["WHO"];
$userdata[$usercount]["id_s"] = $attrib["ID"];
$userdata[$usercount]["date_s"] = $attrib["DATE"];
$userdata[$usercount]["time_s"] = $attrib["TIME"];
$userdata[$usercount]["title_s"] = $attrib["TITLE"];
$userdata[$usercount]["posts_s"] = $attrib["POSTS"];
break;
}
case $name=="TOPIC" : {
$userdata[$usercount]["type_t"] = $attrib["TYPE"];
$userdata[$usercount]["who_t"] = $attrib["WHO"];
$userdata[$usercount]["id_t"] = $attrib["ID"];
$userdata[$usercount]["date_t"] = $attrib["DATE"];
$userdata[$usercount]["time_t"] = $attrib["TIME"];
$userdata[$usercount]["title_t"] = $attrib["TITLE"];
$userdata[$usercount]["posts_t"] = $attrib["POSTS"];
break;
}

default : {$state=$name;break;}
}
}

function endElementHandler ($parser,$name){
global $usercount;
global $userdata;
global $state;
$state='';
if($name=="REPLY") {$usercount++;}
}

function characterDataHandler ($parser, $data) {
global $usercount;
global $userdata;
global $state;
if (!$state) {return;}
}
if (!($xml_parser = xml_parser_create())) die("Couldn't Create Parser.");
xml_set_element_handler( $xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler( $xml_parser, "characterDataHandler");

while( $data = fread($fp, 4096)){
if(!xml_parse($xml_parser, $data, feof($fp))) {
break;}}
xml_parser_free($xml_parser);

echo "\n<table class=\"forum\">\n";
echo "<tr>\n";
echo "<td>Topic Title:</td>\n";
echo "<td>Posts</td>\n";
echo "</tr>\n";

for ($i=0;$i<$usercount1; $i++) {
if ($userdata[$i]["title_i"]) {
	echo "<tr>\n";
	echo "<td>Important: ".$userdata[$i]["title_i"]."</td>\n";
	echo "<td>".$userdata[$i]["posts_i"]."</td>\n";
	echo "</tr>\n";
}
}

for ($i=0;$i<$usercount2; $i++) {
if ($userdata[$i]["title_s"]) {
	echo "<tr>\n";
	echo "<td>Sticky: ".$userdata[$i]["title_s"]."</td>\n";
	echo "<td>".$userdata[$i]["posts_s"]."</td>\n";
	echo "</tr>\n";
}
}

for ($i=0;$i<$usercount3; $i++) {
if ($userdata[$i]["title_t"]) {
	echo "<tr>\n";
	echo "<td>".$userdata[$i]["title_t"]."</td>\n";
	echo "<td>".$userdata[$i]["posts_t"]."</td>\n";
	echo "</tr>\n";
}
}
echo "</table>\n";
?>

 

 

Well This Is The Code For A Forum.

Ive Used Virtually The Exact Same Code For Another Script

But Why Doesn't It Work...?

 

Thnx,

Tarun

Link to comment
https://forums.phpfreaks.com/topic/56986-xml-parsing-error-in-php4/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.