Linera Posted August 30, 2006 Share Posted August 30, 2006 Why am I getting this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/souimapp/public_html/status.php on line 79forif ($serverstatus == 'Down') echo ("<img src="/shared/wow-com/images/icons/serverstatus/downarrow.gif" width="18" height="18">");elseif ($serverstatus == 'Up') echo ("<img src="/shared/wow-com/images/icons/serverstatus/uparrow.gif" width="18" height="18">");elseif ($serverstatus == 'Maitenence') echo ("<img src="/shared/wow-com/images/icons/serverstatus/downarrow.gif" width="18" height="18">");echo ($server) I thought you can use html inside echo. Link to comment Share on other sites More sharing options...
Cronthenoob Posted August 30, 2006 Share Posted August 30, 2006 You can, but you must escape the double quotes or use single quotesso you would do echo "<img src='image.gif' />orecho "<img src=/"image.gif/" />and notecho "<img src="image.gif" />You also don't need the () around the echo statement Link to comment Share on other sites More sharing options...
Linera Posted August 30, 2006 Author Share Posted August 30, 2006 now it gives: Fatal error: Cannot instantiate non-existent class: xmlparser in /home/souimapp/public_html/status.php on line 6for$xml_parse =& new xmlParser(); Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 30, 2006 Share Posted August 30, 2006 (edited) And instead of single quotes, if you want to have double ones in the htnml source code too, you may choose to use escaped double quotes inside double quoted strings like this: $var = "this is a string with \"something\" as a word.";[*Edit:]That last error means (may mean) there is something wrong with the external file, or the internal code, that defines your classes. It may be the URL you use if it is an external file, that is incorrect. Could you show the part that defines your classes, or describe it if it is too long? Edited August 30, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
Linera Posted August 30, 2006 Author Share Posted August 30, 2006 And instead of single quotes, if you want to have double ones in the htnml source code too, you may choose to use escaped double quotes inside double quoted strings like this:[*Edit:]That last error means (may mean) there is something wrong with the external file, or the internal code, that defines your classes. It may be the URL you use if it is an external file, that is incorrect. Could you show the part that defines your classes, or describe it if it is too long? $url = "http://worldofwarcraft.com/realmstatus/status.xml";$server = "Akama"; Link to comment Share on other sites More sharing options...
justsomeguy Posted August 30, 2006 Share Posted August 30, 2006 You are trying to use a class called xmlParser that you have not defined. The class is not built into PHP. Where did you get the code to do that? If you got it from php.net on the XML reference, then this might be the definition for that class: <?phpclass xmlParser{ var $xml_obj = null; var $output = array(); var $attrs; function xmlParser(){ $this->xml_obj = xml_parser_create(); xml_set_object($this->xml_obj,$this); xml_set_character_data_handler($this->xml_obj, 'dataHandler'); xml_set_element_handler($this->xml_obj, "startHandler", "endHandler"); } function parse($path){ if (!($fp = fopen($path, "r"))) { die("Cannot open XML data file: $path"); return false; } while ($data = fread($fp, 4096)) { if (!xml_parse($this->xml_obj, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xml_obj)), xml_get_current_line_number($this->xml_obj))); xml_parser_free($this->xml_obj); } } return true; } function startHandler($parser, $name, $attribs){ $_content = array(); if(!empty($attribs)) $_content['attrs'] = $attribs; array_push($this->output, $_content); } function dataHandler($parser, $data){ if(!empty($data) && $data!="\n") { $_output_idx = count($this->output) - 1; $this->output[$_output_idx]['content'] .= $data; } } function endHandler($parser, $name){ if(count($this->output) > 1) { $_data = array_pop($this->output); $_output_idx = count($this->output) - 1; $add = array(); if ($_data['attrs']) $add['attrs'] = $_data['attrs']; if ($_data['child']) $add['child'] = $_data['child']; $this->output[$_output_idx]['child'][$_data['content']] = $add; } }}?> You need to include that definition on any page you want to use the xmlParser class, or more appropriately, put the definition in its own file and include that file on any page where you want to use it. Link to comment Share on other sites More sharing options...
Linera Posted August 30, 2006 Author Share Posted August 30, 2006 I used that above xml parse class script.See the end results at http://souimappers.post2hostit.com/status.phpIt suppose to place a or in front or the name.Here is the entire script: <?phprequire_once( 'xmlparse.php' );$url = "http://worldofwarcraft.com/realmstatus/status.xml";$server = "Akama";//==========[ XML PARSER ]============================================================= $xml_parse =& new xmlParser(); $err = 1; if( $xml_parse->parse($url) ) { if ( count( $xml_parse->output ) ) { if( is_array($xml_parse->output[0]['child']) ) { foreach ( $xml_parse->output[0]['child'] as $xml_array ) { foreach ( $xml_array as $xml_server ) { if ( $xml_server['N'] == $server ) { $err = 0; switch ( $xml_server['S'] ) { case 0: $serverstatus = 'Down'; break; case 1: $serverstatus = 'Up'; break; case 2: $serverstatus = 'Maitenence'; break; default: $serverstatus = 'Unknown'; } switch ( $xml_server['T'] ) { case 0: $servertype = '(RP-PvP)'; break; case 1: $servertype = 'Normal'; break; case 2: $servertype = '(PvP)'; break; case 3: $servertype = '(RP)'; break; default: $servertype = 'Unknown'; } switch ( $xml_server['L'] ) { case 1: $serverpop = 'Low'; break; case 2: $serverpop = 'Medium'; break; case 3: $serverpop = 'High'; break; case 4: $serverpop = 'Max'; break; default: $serverpop = 'Error'; } } } } } } } else { $err = 1; }if ($serverstatus == 'Down') echo ("<img src='/shared/wow-com/images/icons/serverstatus/downarrow.gif' width='18' height='18'>");elseif ($serverstatus == 'Up') echo ("<img src='/shared/wow-com/images/icons/serverstatus/uparrow.gif' width='18' height='18'>");elseif ($serverstatus == 'Maitenence') echo ("<img src='/shared/wow-com/images/icons/serverstatus/downarrow.gif' width='18' height='18'>");echo ($server)?> Link to comment Share on other sites More sharing options...
justsomeguy Posted August 31, 2006 Share Posted August 31, 2006 Your script is only dealing the the Akama server, which you specify on top. There is an IF statement to check if the current server is the defined server, and only display information for that one.I'm not sure if this makes a difference or not, but the attribute names in the XML sheet are lowercase, and you are checking for uppercase attributes. Change your switch lines from uppercase:switch ( $xml_server['S'] )to lowercase:switch ( $xml_server['s'] )The server status is probably being set to "Unknown", and you don't have it display anything (like a question mark) if the status is unknown. Link to comment Share on other sites More sharing options...
Linera Posted August 31, 2006 Author Share Posted August 31, 2006 I check the server status and its currently up.doing it lower case still doesn't work. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 31, 2006 Share Posted August 31, 2006 Add the print_r line and post what it says: foreach ( $xml_array as $xml_server ) { print_r($xml_server); Or, also, add this to the end:echo "status: {$serverstatus} type: {$servertype} pop: {$serverpop}";And at least see what you are setting the values to be. Link to comment Share on other sites More sharing options...
Linera Posted August 31, 2006 Author Share Posted August 31, 2006 did nothingsee http://souimappers.post2hostit.com/status.php Link to comment Share on other sites More sharing options...
Linera Posted August 31, 2006 Author Share Posted August 31, 2006 got it to work now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now