Forum Moderators: coopster

Message Too Old, No Replies

XML parser in php 5

Can any one explain me this

         

andylonger

11:59 am on Feb 12, 2011 (gmt 0)

10+ Year Member



Hi,
I have done XML ticker in PHP4 which was working great, recently i have upgrade my php to php 5 and get lot of error msg ...

error :- Notice: Use of undefined constant parser - assumed 'parser' in C:\wamp\www\controlpanel\eventupdate.php on line 42

( ! ) Notice: Undefined index: parser in C:\wamp\www\controlpanel\eventupdate.php on line 42

( ! ) Notice: Use of undefined constant parser - assumed 'parser' in C:\wamp\www\controlpanel\eventupdate.php on line 42

( ! ) Notice: Undefined offset: 10 in C:\wamp\www\controlpanel\eventupdate.php on line 62


( ! ) Notice: Use of undefined constant parser - assumed 'parser' in C:\wamp\www\controlpanel\eventupdate.php on line 42
( ! ) Notice: Use of undefined constant parser - assumed 'parser' in C:\wamp\www\controlpanel\eventupdate.php on line 42
( ! ) Notice: Use of undefined constant parser - assumed 'parser' in C:\wamp\www\controlpanel\eventupdate.php on line 42

Here is the Code:-
=================

<?php
session_start();
//global $faction;
$faction ='';
$file = "../Ticker/ticker.xml";

//-------------------------------------------------save to the XML file---------------------------------------------
$strToFile = "";
if(strtoupper(trim($faction)) == "SAVE")
{
$strToFile = $strToFile."<xml id='xmlNews'>\n";
$strToFile = $strToFile."<display>".$sclTickerStatus."</display>\n";
$strToFile = $strToFile."<ticker>\n";
$arrMessages = split("-,",$messagesArray);
for($i = 0; $i < count($arrMessages); $i++)
$strToFile = $strToFile."<message>".$arrMessages[$i]."</message>\n";
//$strToFile = $strToFile."<message>".$TickerMsg[$i]."</message>\n";
$strToFile = $strToFile."</ticker>\n";
$strToFile = $strToFile."</xml>";

//------------------
if (file_exists($file))
{
unlink ($file);
}
$handle = fopen($file,'a+');
if (fwrite($handle, $strToFile) === FALSE)
{
echo 'View Reports'; //View reports
}
fclose($handle);
}
//-----------------------------------------------------XML Parser---------------------------------------------------
global $currTag, $display, $mArray;
$mArray=array();
$depth =array();
function startElement($parser,$name,$attrs)
{
global $depth,$currTag;
$currTag = strtoupper(trim($name));
//$depth++;
$depth[parser]++;
}
function characterData($parser,$data)
{
global $currTag, $display, $mArray;
$curData = trim($data);
if(strlen($curData)>0)
{
if($currTag == "DISPLAY")
$display = strtoupper($curData);
if($currTag == "MESSAGE")
{
$mArray[count($mArray)] = $curData;
}
}
}
function endElement($parser,$name)
{
global $depth;
//$depth--;
$depth[$parser]--;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser,"startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r")))
{
echo 'Error Reading Message'; //Error reading Message
}
while ($data = fread($fp, 4096))
{
if (!xml_parse($xml_parser, $data, feof($fp)))
{
echo 'Error Reading Message';
}
}
xml_parser_free($xml_parser);

//----------------------------------------------------------------------------------------------
echo "<script>";
echo "var messages= new Array(".(count($mArray)+1).");";
for($l=0; $l<count($mArray); $l++)
{
echo "messages[".$l."]='".$mArray[$l]."';";
}
echo "</script>";
?>
<form name="item" action="directing.php?page=events" method="post">
<input name="faction" type="hidden">
<input name="messagesArray" type="hidden">
<table align="center" class="tableForm" width="75%" cellspacing="10">
<tr>
<td>Status:</td>
<td><select name="sclTickerStatus" onChange="submitForm()">
<option value=<?php
echo 'YES';
if($display == "YES")
echo " selected";
?>><?php echo 'On';?></option>
<option value=<?php
echo 'NO';
if($display == "NO")
echo " selected";
?>><?php echo'Off';?></option>
</select>
</td>
</tr>
<tr>
<td valign="top">Event Updates:</td>
<td><textarea id="newmessage" name="newmessage" cols="30" rows="3"></textarea><br />
<input type="button" name=btnAdd value="Add" onClick="addMessage()">
</td>
</tr>
<!---- New Added-->
<tr>
<td colspan="2"><hr noshade width="70%"></td>
</tr>
<tr></tr>
<?php
echo "<tr><td colspan=2>";
echo "<table width=100% border=0 bordercolor='#000000' cellpadding=2 cellspacing=0>";
for($l=0; $l<count($mArray); $l++)
{
echo "<tr class=".($l%2==0?"dark":"light")."><td width=10% align=center valign=center><b>".($l+1)."</b></td><td>".$mArray[$l];
echo "</td><td width=10%>";
if($l != 0)
echo "<a href='javascript:moveUp(".$l.");'><img src='../controlpanel/img/up.gif' border=0> </a>";
if($l != count($mArray)-1)
echo "<a href='javascript:moveDown(".$l.");'><img src='../controlpanel/img/down.gif'' border=0> </a>";
echo "</td><td width=1%><input type=button value='Delete' onClick='deleteMessage(".$l.")'></td></tr>";
}
echo "</table>";
echo "</td></tr>";
?>
</td></tr>
<!--- End of New Added-->
</table>
</form>

andylonger

12:00 pm on Feb 12, 2011 (gmt 0)

10+ Year Member



Any Help or suggestion will be greatly appreciated...!

Matthew1980

4:29 pm on Feb 12, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there andylonger,

Just on a quick scan of your code, this seems to be the cause of your error, php is assuming a constant, because you haven't put '' around the array element this usually references a constant doing that.

$depth[parser]++; needs to be: $depth['parser']++;

If the element was being reference by a variable, this would be what it looks like: $depth[$parser] but I don't know whether or not that is what your needing to use or whether your after the element name...

There may be other little things, but for now that's all I can see.

Cheers,
MRb