Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Isn't the newline already removed?
  2. function createcsv($tablename){
  3.  
  4.     $rs  = $this->SelectAll($tablename);
  5.     $rs1 = $this->SelectAll($tablename);
  6.     if($rs){
  7.         $string ="";
  8.         /// Get the field names
  9.         $fields =  mysql_fetch_assoc($rs1);
  10.         if(!is_array($fields))
  11.           return;
  12.         while(list($key,$val) =each($fields)) {
  13.             $string .= $key.',';
  14.          }
  15.         $string = substr($string,0,-1)."1512"; //removes last and comma and adds a newline
  16.         /// Get the data
  17.         while($row = mysql_fetch_assoc($rs)) {
  18.             while(list($key,$val) =each($row)){
  19.               $row[$key] = strip_tags(html_entity_decode($row[$key])); //strips tangs from the html decoded value
  20.               $row[$key] = str_replace(',',' ',rtrim($row[$key])); //replaces commas with empty spaces from the trimmed value
  21.               $row[$key] = str_replace("1512",' ',$row[$key]);
  22.             }
  23.             $string .= (implode($row,","))."1512";
  24.          }
  25.             echo $string;
  26.  
  27.         //$fp = fopen($this->path.$tablename.".csv",'w');
  28.         //fwrite($fp,$string);
  29.         //fclose($fp);
  30.     }
  31.  
  32. }
  33.        
  34. $row[$key] = str_replace(',',' ',rtrim($row[$key])); //replaces commas with empty spaces from the trimmed value
  35. $row[$key] = str_replace("1512",' ',$row[$key]);