duansha8764 2015-12-15 17:24
浏览 55
已采纳

SSH写入Windows上的文件

I have a problem with the encoding of the text , I do not know what method I use for it so I can ssh using php write to file text with Czech characters as well as characters of other languages ​​. The code currently looks like this :

<?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');
?>

Result in a text file :

set jmeno=t?(C)st
  • 写回答

1条回答 默认 最新

  • dsns47611 2015-12-16 16:14
    关注

    There are a number of factors to consider. What is the character encoding of the *.php file? If it's UTF8 then tést will already be UTF8 encoded and your utf8_encode call will double UTF8 encode tést.

    You also gotta consider the character encoding that C:\Users\server\Desktop\promnene.bat is being loaded with. Are you loading it with Notepad (which supports ANSI, Unicode and UTF-8) or Notepad++ (which supports a whole lot more character encodings) or something else? If you take a CP852 file and load it as a UTF-8 file you won't get the characters you might be expecting.

    Personally, when I work with batch files, I usually just do everything in ANSI / ISO-8859-1. This means no utf8_encode call and no iconv call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?