Я использую скрипт CSV с phpclasses.org. Он извлекает имена столбцов и значения столбцов из таблицы / нескольких таблиц и создает CSV.
Есть одна вещь, которую я не понимаю.
Вот фрагмент кода, на который я смотрю:
function createcsv($tablename){
$rs = $this->SelectAll($tablename);
$rs1 = $this->SelectAll($tablename);
if($rs){
$string ="";
/// Get the field names
$fields = mysql_fetch_assoc($rs1);
if(!is_array($fields))
return;
while(list($key,$val) =each($fields)) {
$string .= $key.',';
}
$string = substr($string,0,-1)."\015\012"; //removes last and comma and adds a newline
/// Get the data
while($row = mysql_fetch_assoc($rs)) {
while(list($key,$val) =each($row)){
$row[$key] = strip_tags(html_entity_decode($row[$key])); //strips tangs from the html decoded value
$row[$key] = str_replace(',',' ',rtrim($row[$key])); //replaces commas with empty spaces from the trimmed value
$row[$key] = str_replace("\015\012",' ',$row[$key]);
}
$string .= (implode($row,","))."\015\012";
}
echo $string;
//$fp = fopen($this->path.$tablename.".csv",'w');
//fwrite($fp,$string);
//fclose($fp);
}
}
2 строки, которые меня интересуют:
$row[$key] = str_replace(',',' ',rtrim($row[$key])); //replaces commas with empty spaces from the trimmed value
$row[$key] = str_replace("\015\012",' ',$row[$key]);
Я думал, rtrim также удаляет новые строки (\ n) ... так почему используется вторая строка $row[$key] = str_replace("\015\012",' ',$row[$key]);
?