Re: Re: Parsing error when XML version is mentioned

From: Date: Mon, 26 Jul 2004 06:23:57 +0000
Subject: Re: Re: Parsing error when XML version is mentioned
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-191866@lists.php.net to get a copy of this message
On 26/07/2004, at 7:29 AM, Scrumpy wrote:
suresh_gen@hotmail.com (Suresh Manoharan) wrote in news:20040725200455.96539.qmail@pb1.pair.com:
I am getting parse error [Parse error: parse error, unexpected T_STRING on line 1] when I use XML version info. <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <head>
[snip]
Can you pls. help me understand why parsing error occurs and how to avoid it.
I just start with "<!DOCTYPE..." on the first line and exclude the "<?xml..." line completely and both parsing and validation are fine.
That's a workaround, not a solution. The problem is that <?... is a PHP short tag, so the PHP engine thinks <?xml version="1.0" encoding="utf-8"?> is PHP code, which it isn't, hence the errors spit out by the PHP engine. Solution 1: Turn off short tags in your php.ini file, so that only <?php ... ?> will turn on the PHP engine. This may require a large rewrite of existing scripts though. Solution 2: Instead of <?xml version="1.0" encoding="utf-8"?> on line 1, use <? echo '<?xml version="1.0" encoding="utf-8"?>'; ?> In other words, let PHP's engine echo the XML declaration, avoiding the PHP parsing errors. Regards --- Justin French http://indent.com.au

« previous php.general (#191866) next »