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:

  1. Make a small change in my php.ini file, or an .htaccess file.
  2. 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

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

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.

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.

Contact Matt

Similar Entries

Stats

147 unique visits since August 2008

Syndicate

Advertisements