views:

54

answers:

5

I have a xml declaration in top of my page like this

   echo "<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="2.0">";

and ?> in the echo seems like php thinks it's a closing statement or something. Am I missing something or is there some other workaround this?

By the way the page is a view in my codeigniter project, if that does matter...

+2  A: 

Just replace outer double quotes with single quotes?

echo '<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="2.0">';
serg
A: 

It's probably your duplicate use of double quotes within a string, as the other answers point out.

Maybe you are also forgetting the surrounding PHP openers.

The full first line should look like this:

<? echo '<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="2.0">';?>
Pekka
+3  A: 

You should escape your quote characters:

echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><rss version=\"2.0\">";
Rubens Farias
+3  A: 

Escape the " or do this instead:

echo '<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="2.0">';

(replacing " with ')

adamse
A: 

syntax should be:

header("Content-Type: application/xml; charset=ISO-8859-1");
echo '<'.'?xml version="1.0" encoding="ISO-8859-1" ?'.'><rss version="2.0">';

Reasoning:

  1. it's very important to set the headers, as some readers go crazy if you don't explicitly declare XML.
  2. the <? and ?> parts of the decleration should be split into benign strings, for good measure.
Nir Gavish