请问怎么清除字符串中的制表符这些

WBOY
Release: 2016-06-23 13:21:39
Original
1956 people have browsed it

 $buf[10] = str_replace("\r\n", '', $buf[10]); //清除换行符  
 $buf[10] = str_replace("\n", '', $buf[10]); //清除换行符  
$buf[10] = str_replace("\t", '', $buf[10]); //清除制表符   

以上我用了,不管用,以下链接是样本文件的下载,是csv格式的,有个地址包含了制表符这些,需要删除掉

http://pan.baidu.com/s/1sjEcrM1


回复讨论(解决方案)

$fn = 'Order_2015-12-01_113045.csv';$s = file_get_contents($fn);preg_match_all('/[\x00-\x1f]/', $s, $m);print_r(array_map('bin2hex', $m[0]));
Copy after login
Array ( [0] => 0a [1] => 0d [2] => 0a [3] => 0d [4] => 0a [5] => 0a )
并没有看到制表符

function lazada_csv_import($filePath){    $file_txt="";    $fp = fopen($filePath, 'r');    while($buf = fgetcsv($fp, '"', ';')){         $file_txt .= implode("\t",$buf)."\t\n";    }        return $file_txt;}
Copy after login


我现在是这样的,输出就多了一行

现在输出txt文件多了一行,用notepad++看是有多了一个换行符的,请问怎么查这个换行符是什么??

str_replace(array("\r\n", "\r", "\n"), " ", $buf[10]);  搞定了

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template