George Botley Posted October 25, 2010 Share Posted October 25, 2010 I am developing a CMS to make Samsung's Digital Display management even easier for a school making use of them. But, one part of the screen uses a slideshow that grabs images from an XML fed file. Here is a snipped of said file. <slide> <url><![CDATA[3.jpg]]></url> <description> <heading>Image Three Title</heading> <paragraph>Image Three description taken from database to appear here.</paragraph> </description> </slide> How would I use PHP to make the document think itself as XML whilst still being able to populate these tags with MySQL fetched data. I.e. <paragraph><? echo "This was taken: Monday...."; ?></paragraph> Any ideas? - Thanks in advance. George. Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/ Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 Re-write it as you output it... Just as you would write an HTML file, you can XML, or anything else... Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126225 Share on other sites More sharing options...
George Botley Posted October 25, 2010 Author Share Posted October 25, 2010 :-\ Little Confused? Rewriteing it like that, doesn't make it dynamic. or does it? I want to populate the values in the XML from data within a MySQL database. Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126243 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 An XML file is just a text file written in a specific format, very similar to a HTML file. It really is that simple. Or are you asking how to use MySQL, because that's a different question... Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126248 Share on other sites More sharing options...
George Botley Posted October 25, 2010 Author Share Posted October 25, 2010 Oh right, I see what you meant now... I would be fine creating a plain text file, populated in PHP using a PHP extension, but will the document be recognised as PHP?? Is there a parameter to type that sets the document output as XML? George. Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126261 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 DTD's, the first line... http://www.w3schools.com/xml/xml_dtd.asp Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126264 Share on other sites More sharing options...
George Botley Posted October 25, 2010 Author Share Posted October 25, 2010 Why does this one not work? <? echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>"; ?> <data> <debug>0</debug> <settings> <folder_images>images</folder_images> <folder_fonts>fonts</folder_fonts> <background> <color transparent="true"><? echo "$color"; ?></color> </background> </settings> </data> Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126268 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 It technically works for me... <?xml version="1.0" encoding="ISO-8859-1" ?> <data> <debug>0</debug> <settings> <folder_images>images</folder_images> <folder_fonts>fonts</folder_fonts> <background> <color transparent="true">yellow</color> </background> </settings> </data> Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126285 Share on other sites More sharing options...
George Botley Posted October 25, 2010 Author Share Posted October 25, 2010 Is that using the code i provided, even with the PHP tags at the top? As my .swf file won't load from it. Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126293 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 I see what you mean. Does this work? It won't load into my directly into my browser. As is it ask me where to save, by commenting out some parameters it'll ask what I want to open it with (and it works with my browsers)... <?php function dumip_it($s,$fn="fn.xml"){ header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$fn); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: '.strlen($s)); ob_clean(); ob_flush(); print $s; exit; } $s="<?xml version='1.0' encoding='ISO-8859-1' ?> <data> <debug>0</debug> <settings> <folder_images>images</folder_images> <folder_fonts>fonts</folder_fonts> <background> <color transparent='true'>yellow</color> </background> </settings> </data>"; dumip_it($s); ?> other... header('Content-Description: File Transfer'); //header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$fn); //header('Content-Transfer-Encoding: binary'); //header('Expires: 0'); //header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); //header('Pragma: public'); header('Content-Length: '.strlen($s)); Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126314 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 function dump_it($s,$fn="fn.xml"){ header('Content-type: text/xml'); header('Content-Length: '.strlen($s)); ob_clean(); ob_flush(); print $s; exit; } Link to comment https://forums.phpfreaks.com/topic/216782-working-with-xml-and-php/#findComment-1126319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.