XML declaration within PHP Nov21 '04
I create my RSS(XML) documents using PHP, so the information is always dynamic.
However, I ran into a problem when attempting to use the standard XML declaration, in my XML documents:
<?xml version="1.0" encoding="utf-8" ?>
Since the XML declaration is similar to the PHP declaration,
<?php
... a big fat parse error is the only obvious output.
As you might guess, the question mark is what causes a bump. To get around this, one of two things has to be done:
- Make a small change in my php.ini file, or an .htaccess file.
- Echo a true string literal to the page, so PHP doesn’t parse the question marks.
Echo a string literal
Since I don’t have (or I am not sure if I have) access to my php.ini file, I went with option 2:
print ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
or...
echo '<?xml version=\"1.0\" encoding=\"utf-8\"?>\n';
This seems to correct the issue.
php.ini or .htaccess
However, I still would like to know how to do it with step 1. I have done some research from the PHP end, and it seems there is a setting within the php.ini file, which needs to be turned on or off.
Also, I have heard there is a line in an .htaccess file that can do the same thing.
I will be looking into it.
Categories: PHP ![]()
Add Feedback (view all)
Leave feedback
What IS the htaccess script that I need? And, everyone, please ignore the 'echo' example from above... I totally messed that one up. Like Bl ... Read more.
http://forums.devarticles.com/archive/t-5039/XHTMLPHP-error This should solve your .htaccess php/xml problem. I had the same issue. ... Read more.
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Similar Entries
- PHP: Skipping index page call in URL (147 recent visits)
- PHP project: convert times to numbers (302 recent visits)
- PHP – passing variables across pages (8551 recent visits)
- Install Apache, PHP, MySQL on Windows (166 recent visits)
- Code mnemonics: PHP implode/explode (376 recent visits)
- Swap banner image with CSS and PHP (658 recent visits)
Stats
147 unique visits since August 2008
Recent Referrers (click)
- output xml declaration php
- xml within php
- declaration
- xml declaration errors
- xml declaration php
- php xml declaration
- output xml declaration in php
- xml declaration in php
- xml in php question marks
- dreamweaver php xml declaration
- htaccess php xml
- php xml declaration
- htaccess xml php
- xml declaration php
- XML declaration php
- xml declaration and php
- declaration php
- php file declaration
- xml declaration php
When you use \n in a single-quoted string (') it will not be parsed as a newline, remember that. And btw: look in to short-tags ;) (for php.i ... Read more.