Php Isn';新行不是已经删除了吗?
我正在使用phpclasses.org上的CSV脚本。它从表/多个表中检索列名和列值,并创建CSV 有一件事我不明白 下面是我正在查看的一段代码:Php Isn';新行不是已经删除了吗?,php,string,Php,String,我正在使用phpclasses.org上的CSV脚本。它从表/多个表中检索列名和列值,并创建CSV 有一件事我不明白 下面是我正在查看的一段代码: function createcsv($tablename){ $rs = $this->SelectAll($tablename); $rs1 = $this->SelectAll($tablename); if($rs){ $string =""; /// Get the f
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);
}
}
我想知道的两行是:
$row[$key] = str_replace(',',' ',rtrim($row[$key])); //replaces commas with empty spaces from the trimmed value
$row[$key] = str_replace("\015\012",' ',$row[$key]);
我还以为会删除新行(\n)。。。那么,为什么第二行
$row[$key]=str_replace(“\015\012”,”,“$row[$key])代码>已使用?rtrim
从字符串的末尾(r=“right”)删除换行符。您引用的行将删除字符串中的任何位置。rtrim
从字符串的末尾(r=“right”)删除换行符。您引用的行将删除字符串中的任何位置。看着您在问题中善意链接的页面,我可以阅读
从字符串的端开始
因此,我可以得出结论,它不会从字符串的任何其他部分删除任何新行 看着你在问题中善意链接的页面,我可以阅读
从字符串的端开始
因此,我可以得出结论,它不会从字符串的任何其他部分删除任何新行