LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-15-2006, 05:46 PM   #1
ayteebee
Member
 
Registered: Jul 2005
Location: Derbyshire
Distribution: Originally Suse 9.1 Professional, currently Knoppix 3.7, migrating to Slackware
Posts: 75

Rep: Reputation: 16
Question Including a file with a question mark in it breaks my php


I'm trying to include the XML declaration and the document type description in my PHP pages, but I seem to be having trouble with the question marks in the XML declaration messing up my PHP server. The page is /pages/index.php and it's including /include/dtd.htm. Here are the [relevant] contents of the two files:

/index.php:
Code:
<?php include '../include/dtd.php'; ?>

<html>

<head>
...
/include/dtd.htm:
Code:
<?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">
This results in the following message:
Code:
Parse error: parse error, unexpected T_STRING in http://www.ayteebee.co.uk/pages/index.php on line 1
Commenting out the ? with a \ works ok, but then it doesn't validate. Here is a list of everything I've tried so far and its result:

1) Commenting out the ? with a \: Parses, but the backslash is left in the source code, so it doesn't validate.
2) Commenting out the entire line with a #: Parses, but again, the hash is left in the source so it doesn't validate.
3) Changing dtd.htm to dtd.php and calling the statements using the echo function: Still won't parse, trying above hacks has the same problems as before.
4) Swapping the <?xml ... ?> and <!DOCTYPE ...> lines around: As 3).
5) Enclosing the ? in single or double quotations: Once again, the quotations are left in the source.
6) I searched the internet and LQ, but didn't seem to find anything, which seems odd, because it can't be an uncommon problem. However I'm not the best webcrawler.

Oh, and I don't have access to the configuration files and stuff (cheap webhost).

So now I'm all out of ideas. How do I include a file without the question mark breaking things?

Thanks in advance.
 
Old 11-15-2006, 11:10 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
A couple of ideas...

try require() in place of include(), if it can't open the file you will get an fatal error. Although from some of your test that doesn't look like the problem.

Try removing the include and putting it in the main file but echo it out, then move that to the external file.
 
Old 11-16-2006, 01:09 PM   #3
ayteebee
Member
 
Registered: Jul 2005
Location: Derbyshire
Distribution: Originally Suse 9.1 Professional, currently Knoppix 3.7, migrating to Slackware
Posts: 75

Original Poster
Rep: Reputation: 16
Thanks Graeme. I'm afraid that using require() didn't make any difference.

Quote:
Try removing the include and putting it in the main file but echo it out, then move that to the external file.
I'm not entirely sure what you mean by this. Do you mean to put the contents of /include/dtd.php into /pages/index.php instead of having the include? I think I might do this as it's going to be the same for all pages anyway and this would involve less processing and disk load on the server. However what do you mean by "echo it out, then move that to the external file"?

It would be nice to deal with this just for the sake of experience.
 
Old 11-16-2006, 01:21 PM   #4
ayteebee
Member
 
Registered: Jul 2005
Location: Derbyshire
Distribution: Originally Suse 9.1 Professional, currently Knoppix 3.7, migrating to Slackware
Posts: 75

Original Poster
Rep: Reputation: 16
Hmm, I don't seem to have brackets around the filename when I use include() or require() but it still seems to work. What's going on there?
 
Old 11-16-2006, 03:40 PM   #5
ayteebee
Member
 
Registered: Jul 2005
Location: Derbyshire
Distribution: Originally Suse 9.1 Professional, currently Knoppix 3.7, migrating to Slackware
Posts: 75

Original Poster
Rep: Reputation: 16
YES!! FINA-FREAKIN-LY!!

It seems that PHP doesn't like having the angle bracket and the question mark together in the form <? or ?>. The solution therefore is to separate them. As follows:

Code:
<?php
        echo '<';
        echo '?';
        echo 'xml version="1.0" encoding="iso-8859-1"';
        echo '?';
        echo '>';
?>
Now the question is, WhyTF didn't I think of that earlier???
 
Old 11-16-2006, 04:14 PM   #6
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
Another solution would have been to simply turn off short_open_tag in your php.ini or in a .htaccess file.
 
Old 11-16-2006, 04:22 PM   #7
ayteebee
Member
 
Registered: Jul 2005
Location: Derbyshire
Distribution: Originally Suse 9.1 Professional, currently Knoppix 3.7, migrating to Slackware
Posts: 75

Original Poster
Rep: Reputation: 16
HAHA! No, scrub that! The problem was that I've put all my pages into the /pages/ directory and I just put an include in /index.php to make it include the page /pages/index.php . This usually worked fine, but for some reason b0rked when it had the XML and doctype declaration in the included file. I don't know why.

Now I've changed the include to a redirect which works fine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script breaks php security on win2003 XAMPP eugene2008 Programming 1 09-10-2006 08:16 AM
Why does my penguin have a question mark? beejayzed General 5 03-23-2004 05:23 PM
iptables mark question paulos Linux - Networking 0 01-21-2004 07:20 AM
-- MARK -- : Why is this repeated in my log file? scarr3d Debian 6 11-19-2003 04:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration