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.
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.
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
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
To take the XML output a step further, you may want to look into the simpleXML
extension in PHP.
See Here for more information
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
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\"?>";