I have this csv2xml.php file
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", true);
ini_set('memory_limit', '24M');
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 .= "\t\t<{$titles[$i]}>";
$r .= $data[$i];
$r .= "</{$titles[$i]}>\n";
}
$row++;
}
fclose($handle);
$r .= "</{$container}>";
return $r;
}
$xml = '<?xml version="1.0" encoding="ISO-8859-1" ?> ';
$xml .= csv2xml('dtifeed.csv', 'petad');
$xmlfile = @fopen('dtifeed.xml', '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";
?>
And I get this results
<?xml version="1.0" encoding="ISO-8859-1" ?> <petad>
<ID>456493</ID>
<Category>P105</Category>
<></>
<></>
<Description>DOGS FOR SALE - They are the best dogs ever. This is a test ad, I would never sell my dogs. Test ad. Please call 928-555-1212.
</Description>
<ID>456501</ID>
<Category>P105</Category>
<></>
<></>
<Description>FIDO MUST GO - But not because we don't love him. Because this is a test ad. The best test ad you've ever read. $1,000. 928-555-1212
</Description>
<ID>456503</ID>
<Category>P110</Category>
<></>
<></>
<Description>KITTENS FREE TO A GOOD HOME - All must go together! There are 101 of them. 928-555-6868.456504</Description>
<ID>456514</ID>
<Category>P125</Category>
<></>
<></>
<Description>A HORSE IS A HORSE unless it's a test ad. Horses for sale, $8,000. 928-111-2323.456516</Description>
</petad>
How can I get rid of the empty tags?
Thank you