I´m a total newbie on PHP.
I´ve a XML file that I´ve to read, and then write as response to a PHP call.
<?php
$my_file = 'myfile.txt';
echo htmlspecialchars(file_get_contents($my_file), ENT_QUOTES);
?>
I tried that, but I guess the response is the xml content but encoded as html. How can I return a proper xml response?
<?php
$my_file = 'file.txt';
$handle = fopen($my_file, 'r');
$sentinel = fread($handle,filesize($my_file));
header("Content-type: text/xml; charset=utf-8");
$content = file_get_contents($stations);
echo $content;
?>
Thanks.
The question should not be how to generate XML response, but how to make the browser understand that the content of the response is XML.
To do so you should use the header function:
header("Content-type: text/xml; charset=utf-8");
Which tells that the content of the response is indeed XML and not html.