H3XED

PHP Include XML File Not Working [Solution]

Aug 16, 2014   Programming   Nick Vogt   Comments
Please note that this post is over a year old and may contain outdated information.
If you've ever tried to include an XML file using the PHP include statement, you may have ran into a compile error or it may simply not work. This is very likely because the XML file starts with the characters <? and the include statement is trying to parse it as PHP.

<?xml version="1.0" encoding="UTF-8"?>
In order to get around this, you'll want to use the file_get_contents or readfile function to get the contents of the XML file. These do not evaluate anything contained in the file.

readfile('file.xml');

Performance: readfile() vs file_get_contents()


The readfile function should be faster, as it outputs the contents of the file directly to the output buffer, rather than putting it into a new string variable. As long as you don't need the contents put into a variable, I recommend using the readfile function.
Share This Post
Twitter

Comments (0)

Share This Post
Twitter
H3XED © Nick Vogt   RSS   Policies   Twitter