0

The post that you want to link this about is not resolving my problem I copy pasted that code and it is still not printing the result as xml format.

I want to create a xml format output from a string, but don't know why it is not working if you can recommend another way to do that.

<?php
    @date_default_timezone_set("GMT"); 
    header("Content-type: text/xml");

  //xml string
  $xml_string=
    "<?xml version='1.0'?>
     <users>
     <user id='398'>
     <name>Foo</name>
     <email>foo@bar.com</email>
     </user>
     <user id='867'>
     <name>Foobar</name>
     <email>foobar@foo.com</email>
     </user>
     </users>";



echo $xml_string;

?>
  • 1
    What do you mean it is not working? – Amir MB Mar 19 '21 at 13:40
  • It is printing a string literal instead of xml format –  Mar 19 '21 at 13:47
  • 1
    If you are _trying_ to say, that your browser does not automatically recognize this as an XML document – then likely it did not receive the correct Content-Type header, so it thinks this is just a normal HTML document. Do you have proper PHP error reporting enabled? Have you checked the response headers using your browser dev tools? – CBroe Mar 19 '21 at 14:04

0 Answers0