How to make xml file from php and mysql

北战南征 提交于 2020-01-11 06:18:14

问题


My fellow friend is building site in flash and he uses XML files to access data in Flash.

I want to build editable CMS so that client can edit stuff.

Now I don't' have any experience with XML.

I know PHP, HTML and Mysql very well.

So how can I change those already build XML files using Mysql and PHP?


回答1:


Maybe going through

http://library.creativecow.net/articles/brimelow_lee/php_mysql/video-tutorial.php

will clear things for you.

Though, use it only to understand the concepts of XML and how it relates to mysql, php and swf. For real work look at libraries that deal with XML such as serializer mentioned in AvatarKava's answer.




回答2:


Output the XML using PHP in exactly the same way the example XML file does and then put this at the top of your code:

header('Content-type: text/xml');

To create the XML file from the database just ouput the data the way you normally would adding XML tags in the right place. Eg:

<news>
<?
    while($item = mysql_fetch_array($data)){
    ?>
    <item>
        <url><?=$item['url']; ?></url>
        <title><?=$item['title']; ?></title>
    </item>
    }
?>
</news>

If you need more assistance, provide the XML file that was given to you with the flash file as a reference.




回答3:


You probably should look at the PEAR XML Serializer Package. It makes it easy to convert a multi-dimensional array into XML.

Here's a decent tutorial: http://articles.sitepoint.com/article/xml-php-pear-xml_serializer



来源:https://stackoverflow.com/questions/2927193/how-to-make-xml-file-from-php-and-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!