简体   繁体   中英

Using PHP for data into an xml file

i am trying to use PHP to give data into an xml file , i am trying to do this simple :

<?xml version="1.0" encoding="utf-8" ?>
<Data>
<Entry>  <?php echo("Hello world");?> </Entry>
</Data>

but , when i am saving this as a .php file it just shows the "Hello world" message , when i am saving it as a .xml file it takes the php script as string and it shows it as it is .... Do you have any idea how it could work ?

header('Content-Type: text/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8" ?>';
echo '<Data><Entry>Hello world</Entry></Data>';

Save it as a PHP script. The XML is being output, but you're just not seeing it (probably) because your default Content-Type is text/html . You can override it, though, using header :

<?php
header('Content-Type: text/xml');
?><?xml version="1.0" encoding="utf-8" ?>
<Data>
<Entry>  <?php echo("Hello world");?> </Entry>
</Data>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM