如何从文本文件中删除空格?我尝试了下面的代码,但我不能:
文件
10400000 2090183800001990000000000000000000001234204321000000000EMPRESA C ECON FEDERAL 20601201405551100162204000000 RETORNO-PRODUCAO 000
10400011T0100030 20090183800001990000000000000000000001234204321000000000EMPRESA 00001622060120140000000000
文件必须保留的方式:
02RETORNO0000000000000000011119999990000000000000000000000000000000000000000104000000000000000201016000000000
代码
$arquivo = fopen($_FILES["Arquivo"]["tmp_name"], "r");
$arquivo = preg_replace('/\s+/', '', $arquivo);
while (!feof($arquivo)) {
$linhas = fread($ler,999999);
$banco = substr($linhas,0,3);
$lote = substr($linhas,4,7);
$registro = substr($linhas,8,8);
}
echo "Banco: " .$banco. "<br>";
echo "Lote: " .$lote. "<br>";
echo "Registro: " .$registro. "<br>";
答案 0 :(得分:0)
您是否尝试过使用file_get_contents
?
试试这个..
$ar = $_FILES["Arquivo"]["tmp_name"];
$arquivo = file_get_contents($ar);
$arquivo = preg_replace('/\s+/', '', $arquivo);