Php SFTP上的文件在开头显示附加字符
我在symfony 3.4中有一个函数,它抛出文件中不存在的字符:Php SFTP上的文件在开头显示附加字符,php,symfony,csv,sftp,phpseclib,Php,Symfony,Csv,Sftp,Phpseclib,我在symfony 3.4中有一个函数,它抛出文件中不存在的字符: use Exception; use phpseclib\Net\SFTP; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\VarDumper\VarDumper; public static function getInfoFile(string $fileName, ContainerInterface
use Exception;
use phpseclib\Net\SFTP;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\VarDumper\VarDumper;
public static function getInfoFile(string $fileName, ContainerInterface $container)
{
$host = $container->getParameter('host');
$sftp = new SFTP($host);
if (!$sftp->login($container->getParameter('user'), $container->getParameter('pass'))) {
throw new Exception('Cannot connect to ' . $host);
}
$file = $sftp->get("/info/$fileName");
vardumper::dump($file); // See Response below
$file = preg_split('/\R/', $file);
reset($file);
// vardumper::dump($file); // This would now return each array element prepended with b"""
return $file;
}
这将返回:
第30行的Service.php:b”“”A;b;C;D;E;F\r\n 1;2;3;4;5;6\r\n
此b“”不在文件中。我尝试用记事本++和Excel打开,但无法看到
当我尝试将substr与此一起使用时,b“”保持不变,实际文件被剪切
我做错了什么?
我想将每行的csv文件读取到一个数组中,而不使用这些神秘的b“”我找到了解决方案
$file = $sftp->get("/info/$fileName");
$file = mb_convert_encoding($file, "UTF-8", "ISO-8859-15" ); // Add this
问题在于编码