User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Nov 2007
Posts: 54
Reputation: jencinas69 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
jencinas69's Avatar
jencinas69 jencinas69 is offline Offline
Junior Poster in Training

weird characters

  #1  
Jul 3rd, 2008
Hello I have a csv file which I am parsing into XML with this code :

<?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 ???
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:50 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC