•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,052 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,464 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 163 | Replies: 0
![]() |
Hello I have a csv file which I am parsing into XML with this code :
this is a sample of the csv where I ran into problems, the parsing works fine, the problem i that when I upload the xml to the site I need it gives me a parsing error because of this character ¥
428977,515,,," ¥ Excellent 2nd income potential! ¥ Weekly Compensation! ¥ Deliveries are only once per week, every Saturday. ¥ Most independent carriers only spend 4 - 6 hours average per week delivering. ¥ Day-Time Delivery. ¥ You'll be delivering a great product-- SUPER SHOPPER! Must have valid AZ driver's license and provide proof of insurance. Call Daniel at 928-539-6910 or stop by and pick up an application at The Sun Subscription & Delivery department: 2055 S. Arizona Avenue, Yuma. $$ EARN EXTRA $$ INTERESTED IN EARNING EXTRA MONEY? DELIVERING YUMA COUNTY'S SUPER SHOPPER!
Is there any way I can get rid of thiis character while I am parsing the csv to xml ???
<?php
/**
* Converts a CSV file to a simple XML file
*
* @param string $file
* @param string $container
* @param string $rows
* @return string
*/
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", true);
function csv2xml($file, $container = 'data', $rows = 'row')
{
$r = "<{$container}>\n";
$row = 0;
$cols = 0;
$titles = array();
$handle = @fopen($file, 'r');
if (!$handle) return $handle;
while (($data = fgetcsv($handle, 1000, ',')) !== FALSE)
{
if ($row > 0) $r .= "\t<{$rows}";
if (!$cols) $cols = count($data);
for ($i = 0; ($i < $cols); $i++)
{
if ($row == 0)
{
$titles[$i] = trim($data[$i]);
continue;
}
if ($titles[$i] == "Description")
{
$r .= ">\n\t\t<description><![CDATA[";
$r .= $data[$i];
$r .= "]]></description>\n";
}
elseif ($titles[$i] == "ID")
$r .= " adID=\"{$data[$i]}\"";
elseif ($titles[$i] == "Category")
$r .= " catID=\"{$data[$i]}\"";
}
if ($row > 0) $r .= "\t</{$rows}>\n";
$row++;
}
fclose($handle);
$r .= "</{$container}>";
return $r;
}
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?> ';
$xml .= csv2xml('dtifeed.csv', 'export', 'ad');
$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";
?>
this is a sample of the csv where I ran into problems, the parsing works fine, the problem i that when I upload the xml to the site I need it gives me a parsing error because of this character ¥
428977,515,,," ¥ Excellent 2nd income potential! ¥ Weekly Compensation! ¥ Deliveries are only once per week, every Saturday. ¥ Most independent carriers only spend 4 - 6 hours average per week delivering. ¥ Day-Time Delivery. ¥ You'll be delivering a great product-- SUPER SHOPPER! Must have valid AZ driver's license and provide proof of insurance. Call Daniel at 928-539-6910 or stop by and pick up an application at The Sun Subscription & Delivery department: 2055 S. Arizona Avenue, Yuma. $$ EARN EXTRA $$ INTERESTED IN EARNING EXTRA MONEY? DELIVERING YUMA COUNTY'S SUPER SHOPPER!
Is there any way I can get rid of thiis character while I am parsing the csv to xml ???
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Cannot delete file (Windows 9x / Me)
- Internet explorer displaying odd characters (Web Browsers)
- Read in a file and store in char array (C)
- Need help with my console database app, program reading or writing incorrectly (C++)
- new to windows apps (C)
- Ideas for a new XT compatible OS... (Techies' Lounge)
- People who can't post threads (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: PHP Date and Time issue
- Next Thread: How to retrive the values from the database


Linear Mode