Question:
Creating an xml file from php and mysql?
ashleyemma
2010-08-10 10:21:34 UTC
How do I create an xml file from php for other people to use the content for their own work? Thanks
Three answers:
Chris C
2010-08-10 11:49:08 UTC
An XML is merely a text file that has a defined layout (which is dependent upon the application).

So, you could simply use the printf(), echo(), or print() commands, like this:

   $title = "This is my title";

   printf("\n\t%s", $title);



Of course, if you're generating the XML and storing it into a file and then sending it in an email, then you want to use the fwrite() command.



Or if you have PHP version 5.1.2 or greater, you can use the XML functions provided by the language, such as this: http://us.php.net/manual/en/function.xmlwriter-open-uri.php
?
2010-08-10 11:38:11 UTC
xml_parser_create



You may want to review the PHP manual. If you are using an open sourced PHP program like moodle, or wordpress XML parsing tools are available to add on to the applicaiton.
guru
2014-08-24 21:23:36 UTC
The Sample PHP code is
header ("content-type: text/xml");

mysql_connect('localhost','root','') or die(mysql_error());

mysql_select_db('fitness') or die(mysql_error());

$xml='';

$qr=mysql_query("SELECT * FROM `f_img` order by id desc") or die(mysql_error());

$xml.='';

while($res=mysql_fetch_array($qr))

{

$xml.=''.$res['name'].''.$res['state'].''.$res['country'].'';

}

$xml.='
';

echo $xml;

?>


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...