Current location: Hot Scripts Forums » Programming Languages » PHP » XML causes PHP parse error


XML causes PHP parse error

Reply
  #1 (permalink)  
Old 08-06-08, 10:30 PM
greenpig greenpig is offline
Newbie Coder
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
XML causes PHP parse error

Hi, I'm new to this site and relatively new to PHP, so my apologies if this has been answered before (a quick search of the forum didn't turn up anything).

I code my web pages in XHTML and they all start:

HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
I want to parse these pages for PHP, but when I do the first of these lines throws up an "unexpected T_STRING" parse error. A look at phpinfo() showed me that "short_open_tag=on" by default on my hosting service. So I created a custom php.ini file that sets short_open_tag=off, and now phpinfo() confirms that short tags are off. However I'm still getting the same parser error:

Parse error: syntax error, unexpected T_STRING in [URL] on line 1

I know it is possible to work around this problem by wrapping the offending line in a <?php echo ... ?> command, but this breaks the syntax checker in BBEdit, where I do my coding. Does anyone have any ideas what else might be causing the parser to choke on this line?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-08-08, 10:07 PM
axilant axilant is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

<?PHP echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"?>

replace your first line with that

I understand that you are concerned about bbedit, it sounds like it is broken anyways if it doesn't parse correctly.

If you can, link me your php info and ill take a look

Last edited by axilant; 08-08-08 at 10:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-08-08, 10:17 PM
greenpig greenpig is offline
Newbie Coder
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, but as I said in my post I'm aware of this solution. Unfortunately it breaks the syntax checker in my code editor. I really want to understand why I'm getting the error in the first place without having to resort to workarounds.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-08-08, 11:02 PM
greenpig greenpig is offline
Newbie Coder
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
The problem with BBedit is that when it's checking HTML syntax it expects the first line to be either a DOCTYPE or "<?xml... ?>. In the absence of either of these, it defaults to assuming the code is HTML 4.01 Transitional, and then it finds errors with my XHTML code. I agree this is kind of clumsy, but the program is great in all the other respects that matter to me, so I'd like to find a solution to the problem that won't conflict with it.

PHP info is on this page. Thanks for taking a look!

Last edited by greenpig; 08-08-08 at 11:30 PM. Reason: Adding link
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-13-08, 03:02 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Did you restart apache after editing the ini?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 08-21-08, 02:23 PM
greenpig greenpig is offline
Newbie Coder
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Well, it isn't my Apache to restart -- it's my hosting provider's. Do I need to restart? Again, the odd thing is that phpinfo() shows that short_open_tag=off, so it seems to be reading my .ini file. But it doesn't solve my problem!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 08-21-08, 02:54 PM
greenpig greenpig is offline
Newbie Coder
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Figured it out, finally

A stupid error on my part: I'd stuck the line
Code:
AddHandler php-cgi .php
in my .htaccess, but I neglected to add .html. So my .php file that ran phpinfo() worked, and my .html files didn't. Duh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error p51d78th PHP 3 01-02-08 09:52 AM
xml to mysql using php - urgent mianriz PHP 1 12-21-06 04:51 PM
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING o danielta PHP 2 07-11-06 01:12 PM
Parse error: parse error, unexpected $ in... keefermedia PHP 4 04-23-06 12:21 PM
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE | help? culticka PHP 1 11-25-04 04:10 PM


All times are GMT -5. The time now is 06:18 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.