Hey Rob at the end I did not need the email thing this is the final copy of code
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", true);
ini_set('memory_limit', '24M');
$file = "pets_feed_" . date("Ymd") . ".xml";// - for yyyymmdd
if (!file_exists($file)) touch($file);
$fh = fopen($file, "r");
function csv2xml($file, $container = 'data')
{
$r = "<{$container}>\n";
$row = 0;
$cols = 0;
$titles = array();
$handle = @fopen($file, 'r');
if (!$handle) return $handle;
while (($data = fgetcsv($handle, 1000, ',')) !== FALSE)
{
if (!$cols) $cols = count($data);
for ($i = 0; $i < $cols; $i++)
{
if ($row == 0)
{
$titles[$i] = $data[$i];
continue;
}
$r .= trim($data[$i]) != ""?"\t\t<{$titles[$i]}>$data[$i]</{$titles[$i]}>\n":"";
}
$row++;
}
fclose($handle);
$r .= "</{$container}>";
return $r;
}
$xml = '<?xml version="1.0" encoding="ISO-8859-1" ?> ';
$xml .= csv2xml('petsfeed.csv', 'petad');
$xmlfile = @fopen($file, "wb") or die('Could not open XML file for writing');
fwrite($xmlfile, $xml) or die('Could not write string to XML file');
fclose($xmlfile);
echo "Successfully wrote the XML file";
?>
The only problem is that I need the <petad> to open and close every ad instead of opening at the beginning of the file and closing at the end
any ideas?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Offline 68 posts
since Nov 2007