-2

hi friends a simple question.

How to print the following line from PHP echo

<?xml version="1.0" encoding="iso-8859-1"?>

I am confused with escape sequences.

Surjya Narayana Padhi
  • 7,741
  • 25
  • 81
  • 130
  • I think you are looking for that [http://stackoverflow.com/questions/486757/how-to-generate-xml-file-dynamically-using-php][1] [1]: http://stackoverflow.com/questions/486757/how-to-generate-xml-file-dynamically-using-php – Vijay Verma Feb 05 '13 at 06:54
  • Would you consider selecting an answer? – jdstankosky Mar 12 '13 at 13:32

6 Answers6

1

Printing the XML

You can either escape the double quotes like so:

echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";

or you can use single quotes, and therefore no escaping is needed:

echo '<?xml version="1.0" encoding="iso-8859-1"?>';

Alternatively, you can also use the print() method like so:

print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";

or

print '<?xml version="1.0" encoding="iso-8859-1"?>';

Which one you use, depends on what you would like to achieve. In most cases echo is the better option as it is ever so slightly faster.

See Here for the differences between echo and print

Outputting XML to the browser

However, if you are trying to generate XML, then it is also important to output the correct headers for the document, like so:

header("Content-Type: text/xml");

This will tell the browser to interpret what you output, as XML

Advanced XML Outputting

To take the XML output a step further, you may want to look into the simpleXML extension in PHP.

See Here for more information

Community
  • 1
  • 1
Ben Carey
  • 16,540
  • 19
  • 87
  • 169
  • 1
    @DevangRathod read the question! He may use the word print, but he asks how to print this using `echo` – Ben Carey Feb 05 '13 at 06:52
0

Use single quotes:

echo '<?xml version="1.0" encoding="iso-8859-1"?>';
Lauris
  • 1,085
  • 10
  • 16
0
echo '<?xml version="1.0" encoding="iso-8859-1"?>';
Zevi Sternlicht
  • 5,399
  • 19
  • 31
0

you can screen them using "\" (if you have some var in this statement) i.e. echo "<?xml version=\"1.0\" encoding=\"iso-8859-1"?>\";
If no var then just '<?xml version="1.0" encoding="iso-8859-1"?>'
Or you can use $text = '<?xml version="1.0" encoding="iso-8859-1"?>'; echo $text;
Or you can use Heredoc (use it for big text only)

And read about difference between ' and " in PHP

Alexander
  • 177
  • 2
  • 9
0
echo <<<XML
<?xml version="1.0" encoding="iso-8859-1"?>
XML;
user1629569
  • 661
  • 1
  • 4
  • 17
0

You have to put header (to let the browser know how to render the display):

header ("Content-Type:text/xml");
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
laxonline
  • 2,657
  • 1
  • 20
  • 37