# Php code generating an XML file Help

**URL:** <https://forum.kirupa.com/t/php-code-generating-an-xml-file-help/305011>\
**Category:** programming\
**Created:** [February 18, 2010, 12:44am UTC](https://forum.kirupa.com/t/php-code-generating-an-xml-file-help/305011 "2010-02-18T00:44:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![samy4movies](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/samy4movies/32/8371_2.png) [@samy4movies](https://forum.kirupa.com/u/samy4movies)\
**Post date:** [February 18, 2010, 12:44am UTC](https://forum.kirupa.com/t/php-code-generating-an-xml-file-help/305011/1 "2010-02-18T00:44:51Z")

</div>

Hi PHP gurus,  
I have a php code that I found very helpful to generate an xml file.  
It get the files from a folder an creates the xml file, but I need to know how can I generate a #CDATA-Section, because this xml file will be used to see images and videos in a 3D carrousel that I have in my website: [http://anaheimspanish.net](http://anaheimspanish.net)  
I also have some weird output but I’ll be happy with one solution at the time.  
You can run the php file to see the output: [http://anaheimspanish/FLASH\_DIR/3D\_GALLERY/Videos/Videos/xml\_videos.php](http://anaheimspanish/FLASH_DIR/3D_GALLERY/Videos/Videos/xml_videos.php)  
This is the php code:

\<?php  
$myfeed = new RSSFeed();  
$myfeed-\>SetChannel(‘[http://anaheimspanish.net/](http://anaheimspanish.net/)’,  
‘This is my web site’,  
‘The latest files in my directory’,  
‘en-us’,  
‘[anaheimspanish.net](http://anaheimspanish.net)’,  
‘[anaheimspanish.net](http://anaheimspanish.net)’,  
‘The Latest Files in my Directory’);  
// $myfeed-\>SetImage(‘[http://anaheimspanish.net/mylogo.jpg](http://anaheimspanish.net/mylogo.jpg)’);  
// Open the current directory (or specify it) and grab only .flv files …  
$dir = opendir ("./");  
while (false !== ($file = readdir($dir))) {  
if (strpos($file, ‘.flv’,1)||strpos($file, ‘.flv’,1) ) {  
//$myfeed-\>SetItem(“[http://anaheimspanish.net/FLASH\_DIR/3D\_GALLERY/$file](http://anaheimspanish.net/FLASH_DIR/3D_GALLERY/%24file)”, “This is the file: $file”, “”);  
$myfeed-\>SetItem(“FLASH\_DIR/3D\_GALLERY/$file”, “The file is: $file”, “”);  
}  
}  
// Output the XML File … you could write it to the directory instead.  
//echo $myfeed-\>output();  
// Write the XML File to a file.  
$fp = fopen(‘video\_xml.xml’, ‘w’);  
fwrite($fp, $myfeed-\>output());  
fclose($fp);  
class RSSFeed {  
// VARIABLES  
// channel vars  
var $channel\_url;  
var $channel\_title;  
var $channel\_description;  
var $channel\_lang;  
var $channel\_copyright;  
var $channel\_date;  
var $channel\_creator;  
var $channel\_subject;  
// image  
var $image\_url;  
// Items  
var $Items = array();  
var $nrItems;

// FUNCTIONS  
// constructor  
function RSSFeed() {  
$this-\>nrItems=0;  
$this-\>channel\_url=’’;  
$this-\>channel\_title=’’;  
$this-\>channel\_description=’’;  
$this-\>channel\_lang=’’;  
$this-\>channel\_copyright=’’;  
$this-\>channel\_date=’’;  
$this-\>channel\_creator=’’;  
$this-\>channel\_subject=’’;  
$this-\>image\_url=’’;  
}  
// set channel vars  
function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject, $Thumb, $Name, $ToolTips, $Link) {  
$this-\>channel\_url=$url;  
$this-\>channel\_title=$title;  
$this-\>channel\_Description=$Description;  
$this-\>channel\_lang=$lang;  
$this-\>channel\_copyright=$copyright;  
$this-\>channel\_date=date(“Y-m-d”).‘T’.date(“H:i:s”).’+01:00’;  
$this-\>channel\_creator=$creator;  
$this-\>channel\_subject=$subject;  
$this-\>channel\_Thumb=$Thumb;  
$this-\>channel\_Name=$Name;  
$this-\>channel\_ToolTips=$ToolTips;  
$this-\>channel\_Link=$Link;  
$this-\>channel\_File=$File;  
$this-\>channel\_FileInfo=$FileInfo;

```
}
// set image
function SetImage($url) {
    $this-&gt;image_url=$url;  
}
// set Item
function SetItem($url, $Description, $Thumb, $Name, $ToolTips, $Link, $File, $FileInfo) {
    $this-&gt;Items[$this-&gt;nrItems]['url']=$url;
    $this-&gt;Items[$this-&gt;nrItems]['Thumb']=$Thumb;
    $this-&gt;Items[$this-&gt;nrItems]['Description']=$Description;
    $this-&gt;Items[$this-&gt;nrItems]['Link']=$URL;
    $this-&gt;Items[$this-&gt;nrItems]['Name']=$Name;
    $this-&gt;Items[$this-&gt;nrItems]['ToolTips']=$ToolTips;
    $this-&gt;Items[$this-&gt;nrItems]['File']=$File;
    $this-&gt;Items[$this-&gt;nrItems]['FileInfo']=$FileInfo;
    $this-&gt;nrItems++;   
}
// output feed
function Output() {
    $output = '&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;'."

```

“;  
$output .= '\<rdf:RDF xmlns:rdf=“[http://www.w3.org/1999/02/22-rdf-syntax-ns#](http://www.w3.org/1999/02/22-rdf-syntax-ns#)” xmlns=“[http://purl.org/rss/1.0/](http://purl.org/rss/1.0/)” xmlns:slash=“[http://purl.org/rss/1.0/modules/slash/](http://purl.org/rss/1.0/modules/slash/)” xmlns:taxo=“[http://purl.org/rss/1.0/modules/taxonomy/](http://purl.org/rss/1.0/modules/taxonomy/)” xmlns:dc=“[http://purl.org/dc/elements/1.1/](http://purl.org/dc/elements/1.1/)” xmlns:syn=“[http://purl.org/rss/1.0/modules/syndication/](http://purl.org/rss/1.0/modules/syndication/)” xmlns:admin=“[http://webns.net/mvcb/](http://webns.net/mvcb/)” xmlns:feedburner=”[URL=“[http://rssnamespace.org/feedburner/ext/1.0&quot;&gt;](http://rssnamespace.org/feedburner/ext/1.0&quot;&gt;)’.&quot; “][http://rssnamespace.org/feedburner/ext/1.0"\>’."](http://rssnamespace.org/feedburner/ext/1.0%22%3E'.%22)  
“;  
$output .= '\<channel rdf:about=”’.$this-\>channel\_url.’”\>’.”  
“;  
$output .= ‘\<Title\>’.$this-\>channel\_Title.’\</Title\>’.”  
“;  
$output .= ‘\<Link\>’.$this-\>channel\_url.’\</Link\>’.”  
“;  
$output .= ‘\<Description\>’.$this-\>channel\_Description.’\</Description\>’.”  
“;  
$output .= ‘\<dc:language\>’.$this-\>channel\_lang.’\</dc:language\>’.”  
“;  
$output .= ‘\<dc:rights\>’.$this-\>channel\_copyright.’\</dc:rights\>’.”  
“;  
$output .= ‘\<dc:date\>’.$this-\>channel\_date.’\</dc:date\>’.”  
“;  
$output .= ‘\<dc:creator\>’.$this-\>channel\_creator.’\</dc:creator\>’.”  
“;  
$output .= ‘\<dc:subject\>’.$this-\>channel\_subject.’\</dc:subject\>’.”  
“;  
$output .= ‘\<Items\>’.”  
“;  
$output .= ‘\<rdf:Seq\>’;  
for($k=0; $k\<$this-\>nrItems; $k++) {  
$output .= '\<rdf:li rdf:resource=”’.$this-\>Items[$k][‘url’].’"/\>’."  
“;  
};  
$output .= ‘\</rdf:Seq\>’.”  
“;  
$output .= ‘\</Items\>’.”  
“;  
$output .= '\<video rdf:resource=”’.$this-\>video\_url.’"/\>’."  
“;  
$output .= ‘\</channel\>’.”  
“;  
for($k=0; $k\<$this-\>nrItems; $k++) {  
$output .= '\<Item rdf:about=”’.$this-\>Items[$k][‘url’].’"\>’."  
“;  
$output .= '\<Thumb Location=”’.$this-\>Items[$k][‘Thumb’].’"\>\</Thumb\>’."  
“;  
$output .= '\<Link URL=”’.$this-\>Items[$k][‘url’].’"\>.\</Link\>’."  
“;  
$output .= ‘\<Description\>’.$this-\>Items[$k][‘Description’].’\</Description\>’.”  
“;  
$output .= ‘\<File Type=“video” Length=“6”\>’.$this-\>Items[$k][‘File’].’\</File\>’.”  
“;  
$output .= ‘\<FileInfo\>’.$this-\>Items[$k][‘FileInfo’].’\</FileInfo\>’.”  
“;  
$output .= ‘\<Name’.$this-\>Items[$k][‘Name’].’\>\</Name\>’.”  
“;  
$output .= ‘\<ToolTips cdata=“this is the info I want”\>’.$this-\>Items[$k][‘ToolTips’].’”\>\</ToolTips\>’."  
“;  
$output .= ‘\</Item\>’.”  
“;  
};  
$output .= ‘\</rdf:RDF\>’.”  
";  
return $output;  
}  
};  
?\>

AND THIS IS THE OUTPUT I GET:(see the attached snap picture php\_xml.png

As you can see the tag for ToolTips cdata is in red which is an attribute, but I need it as #cdata-section.  
How can I get this done?  
What am I missing in my output?  
If this code is to complicated I would like to know as well that. If there’s another option. I’ll be happy to try.  
Thanks for you time and help.
