本来在unix世界换行就用/n来代替,但是windows为了体现他的不同,就用/r/n,更有意思的是在mac中用/r。因此unix系列用 /n,windows系列用 /r/n,mac用 /r
$content=str_replace("\n","",$content);
echo $content;
str_replace("\r\n","",$str);
$content=preg_replace("/\s/","",$content);
echo $content;
/1、使用str_replace 来替换换行
$str = str_replace(array("/r/n", "/r", "/n"), "", $str);
//2、使用正则替换
$str = preg_replace('//s*/', '', $str);
//3、使用php定义好的变量 (建议使用)
$str = str_replace(PHP_EOL, '', $str);
$str = str_replace(PHP_EOL, '', $str);
foreach ($dataObj as $key => $objV) {
$csv_data_row = '';
foreach ($headerKey as $kv) {
if (in_array($kv,['onlie_remark'])){
$csv_data_row .= preg_replace("/\s/","",$objV->$kv).',';
}else if(preg_match('/,/',$objV->$kv)){
$csv_data_row .= strtr($objV->$kv,',','|').',';
}else{
$csv_data_row .= $objV->$kv.',';
}
}
$csv_data .= $csv_data_row.PHP_EOL;
}