tags:

views:

79

answers:

4

The following outputs double quotes. How can I get it to output single quotes?

<?php
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<I song='song'>";
echo $xml_output;

The output is <I song="song" />

Output should be <I song='song' />

A: 

using your code as-is, will output single quotes around the song value, but viewing it in IE or another xml viewer might show it differently.

try checking with wget or view source.

jspcal
A: 

The output is probably correct, but you are reading it after it's passed through some XML parser (for example, in your web browsers "show source" window).

Emil Vikström
+1  A: 

It's not due to PHP engine.

$ cat so.php 
<?php
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<I song='song'>";
echo $xml_output;
?>

$ php -q so.php 
<?xml version="1.0"?>
<I song='song'> 
Chandra Patni
+1  A: 

Are you looking at the output in Firebug (or similar)? Browsers (and extensions) may change the quotes (and formatting and other things) to suit but that doesn't mean they aren't getting sent like you're doing.

There's nothing wrong with your code. A single quote in a double-quote string is a single quote.

cletus