Php 从文本文件中删除空格
如何从文本文件中删除空格?我尝试了以下代码,但无法: 文件Php 从文本文件中删除空格,php,Php,如何从文本文件中删除空格?我尝试了以下代码,但无法: 文件 10400000 2090183800001990000000000000000000001234204321000000000EMPRESA C ECON FEDERAL 20601201405551100162204000000 RETORNO-PRODUCAO
10400000 2090183800001990000000000000000000001234204321000000000EMPRESA C ECON FEDERAL 20601201405551100162204000000 RETORNO-PRODUCAO 000
10400011T0100030 20090183800001990000000000000000000001234204321000000000EMPRESA 00001622060120140000000000
文件必须如何保存:
0200000000000001111199999000000000000000000000000000000000000000000000000000104000000000000000201016000000000
代码
$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>";
$arquivo=fopen($_文件[“arquivo”][“tmp_名称”],“r”);
$arquivo=preg_replace('/\s+/',''.$arquivo);
而(!feof($arquivo)){
$linhas=fread($ler,999999);
$banco=substr($linhas,0,3);
$lote=substr($linhas,4,7);
$registro=substr($linhas,8,8);
}
echo“Banco:”.$Banco。“
”;
回声“Lote:”.$Lote。“
”;
echo“Registro:”.$Registro。“
”;
您是否尝试过使用文件获取内容
试试这个
$ar = $_FILES["Arquivo"]["tmp_name"];
$arquivo = file_get_contents($ar);
$arquivo = preg_replace('/\s+/', '', $arquivo);
代码的可能副本根本不会更改文件,它只是从中读取。如果您想从文件中删除某些内容,那么至少应该对其进行写入。对。我更改了我的帖子。我尝试使用以下代码:
$arquivo=preg_replace('/\s+/','.$arquivo)代码>在while()之前,但当我运行时,它会继续读取并使浏览器崩溃。您所做的更改是毫无意义的preg_replace
可用于字符串,但$arquivo
是一个文件句柄。你还没有写任何东西。