Reputation: 11331
I'm working on a school project where we have to encode literary texts into XML, and then post them on our web pages. I have a web page that mostly uses HTML and CSS, but occasionally uses a PHP include in order to get all my headers and footers modular and in separate files. The problem with this setup is, when I have a php include to include (i.e. import) my XML file, I get this parsing error: Parse error: parse error in /home1/j/jpr226/public_html/homestead.xml on line 1
, where line 1 is just the xml declaration, something like <?xml version="1.0"?>
.
If I copy-and-paste the XML file into the HTML file, it seems to work roughly as expected, but when I use php to include this file, I get this error.
I'm guessing PHP is trying to parse this XML file somehow, and when it can't do that, it generates this error. Is there a way to tell PHP to lay off, and stop trying to interpret my XML file?
This is from http://i5.nyu.edu/~jpr226/texts.php
Upvotes: 0
Views: 261
Reputation: 163603
Turn off short open tag in PHP.ini.
http://php.net/manual/en/ini.core.php
Upvotes: 0
Reputation: 39386
include()
anything that's not php. Read the file with file_get_contents()
instead.short_open_tag
ini directive. When short_open_tag is on, <?
is equivalent to <?php
.Upvotes: 2
Reputation: 17139
Did you try HTML-encoding the XML?
$myXMLCode = htmlspecialchars($myXMLCode);
echo $myXMLCode;
Edit: It sounds like the PHP preprocessor is reading <?
as a starting PHP tag. Did you disable short tags?
ini_set("short_open_tag", 0);
Upvotes: 0