Jump to content

Working with XML and PHP


George Botley

Recommended Posts

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

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.

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>

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>

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));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.