繁体   English   中英

SSH在Windows上写入文件

[英]SSH write to a file on windows

我的文本编码有问题,我不知道我使用什么方法,所以我可以使用php ssh来写文件,文件中包含捷克语字符以及其他语言的字符。 当前代码如下:

<?php
$appname = "tést";
function prevedKodovani($string)
{
$string = iconv("utf-8", "CP852//TRANSLIT", $string);
return $string;
}
include('Net/SSH2.php');
$ssh = new Net_SSH2('ip');

if (!$ssh->login('jmeno', 'heslo')) {

    exit('Login Failed');

}

echo $ssh->exec('cmd /c echo set jmeno='.prevedKodovani(utf8_encode($appname)).'>>C:\Users\server\Desktop\promnene.bat');
?>

结果为文本文件:

set jmeno=t?(C)st

有许多因素需要考虑。 * .php文件的字符编码是什么? 如果它是UTF8,则tést将已经是UTF8编码的,并且您的utf8_encode调用将把UTF8编码的tést

您还必须考虑加载C:\\Users\\server\\Desktop\\promnene.bat的字符编码。 您要使用Notepad(支持ANSI,Unicode和UTF-8)或Notepad ++(支持更多的字符编码)或其他方式加载它吗? 如果您使用CP852文件并将其作为UTF-8文件加载,您将不会得到预期的字符。

就个人而言,当我处理批处理文件时,通常只需要执行ANSI / ISO-8859-1中的所有操作。 这意味着没有utf8_encode调用,也没有iconv调用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM