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 正在加载的字符编码。你是用记事本(它支持 ANSI、Unicode 和 UTF-8)还是 Notepad++(它支持更多的字符编码)或其他东西加载它?如果您采用 CP852 文件并将其作为 UTF-8 文件加载,您将无法获得您可能期望的字符。

就我个人而言,当我使用批处理文件时,我通常只是在 ANSI / ISO-8859-1 中做所有事情。这意味着没有 utf8_encode 调用也没有 iconv 调用。