Archive
This post is archived and may contain outdated information. It has been set to 'noindex' and should stop showing up in search results.
This post is archived and may contain outdated information. It has been set to 'noindex' and should stop showing up in search results.
PHP Include XML File Not Working [Solution]
Aug 16, 2014ProgrammingComments (0)
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.
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.
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.
<?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.