修改unix服务器的编码,Unix SSH服务器上的Cron Job:UTF-8编码?(Cron Job on Unix SSH server : UTF-8 encoding?)...

Unix SSH服务器上的Cron Job:UTF-8编码?(Cron Job on Unix SSH server : UTF-8 encoding?)

在PHP 5中运行,我尝试了以下两个命令从ISO-8859-1字符串上传到链接到UTF-8网页的UTF-8数据库:

$data[] = utf8_encode((string)$child);

... 要么:

$data[] = convertToUtf8((string)$child);

function convertToUtf8($text) {

// cURL('http://'.$url);

preg_match('/

$charset = $matches[2];

if($charset)

return mb_convert_encoding($text, 'UTF-8', $charset);

else

return $text;

}

如果我通过从浏览器访问文件直接执行PHP脚本,其中任何一个就像魅力一样:«é»import是它的好法语自我。 但是,当我尝试从Unix终端SSH(cron job OR命令行)执行相同的脚本时,它不会转换代码,因此«é»显示为«Ã©»。

有任何想法吗?? 我已经尝试删除cron作业并替换脚本以确保代码正在通过。 这变得令人发狂!

更新 - 解决方案

事实证明,这个特殊功能需要更高版本的PHP。 使用以下命令在终端中执行它(并在cron作业中编写命令)可以解决问题:

php5.4 xmluploader.php

Running in PHP 5, I have tried the following two commands to upload from a ISO-8859-1 string to a UTF-8 database that links to UTF-8 web pages:

$data[] = utf8_encode((string)$child);

... or:

$data[] = convertToUtf8((string)$child);

function convertToUtf8($text) {

// cURL('http://'.$url);

preg_match('/

$charset = $matches[2];

if($charset)

return mb_convert_encoding($text, 'UTF-8', $charset);

else

return $text;

}

If I execute the PHP script directly by accessing the file from the browser, either one of these works like a charm : the « é » imported is its nice French self. HOWEVER, when I try to execute the same script from a Unix terminal SSH (cron job OR command line), it does not convert the code and so the « é » shows up as « Ã© ».

Any ideas?? I've tried deleting the cron job and replacing the script to make sure the code was going through. This is getting maddening!

Update - the solution

It turns out this particular functionality needs a later version of PHP. Executing it in the Terminal with the following command (and writing the command as such in the cron job) takes care of the problem:

php5.4 xmluploader.php

原文:https://stackoverflow.com/questions/26701572

更新时间:2019-12-04 12:25

最满意答案

好吧,顺便说一下,我当然要探索一些编码见解,但最后,解决方案非常简单。

我打算输入这份工作

php myjob.php

这是一个非首发,因为我的服务器上的默认版本太原始,并且不包含函数utf8_encode或mb_convert_encoding。 因此,我现在使用以下命令启动作业:

php5.4 myjob.php

......它就像一个魅力。

Well, along the way I certainly got to explore some encoding insights but in the end, the solution was quite embarrassingly simple.

I was running the job by typing in

php myjob.php

That was a non-starter, because the version by default on my server was too primitive and did not contain the functions utf8_encode or mb_convert_encoding. Therefore, I now start the job with the following command:

php5.4 myjob.php

... and it works like a charm.

相关问答

部分原因是文件系统期望NUL('\ 0')字节终止文件名,所以UTF-16将无法正常工作。 你必须修改很多代码才能做出改变。 Partly because the file systems expect NUL ('\0') bytes to terminate file names, so UTF-16 would not work well. You'd have to modify a lot of code to make that change.

它不会更改文件的编码。 它会改变文件名的编码(每个客户端都希望了解的内容)。 由谁允许? NTFS使用16位代码点,Windows可以根据您的要求(它将尝试将它们转换为您要求的编码),以不同的编码公开文件名。 现在...那个位(你怎么问)取决于你使用的特定svn客户端。 对我来说听起来像是TortoiseSVN中的一个bug。 编辑添加: 啊。 我误解了症状。 svn服务器将所有内容存储在utf-8中(似乎它已经成功)。 后提交钩子是无法从UTF-8转换的位。 如果我明白你正在说的是什么,服务器上

...

您必须确保发出的sed命令是UTF-8编码的。 您可以通过以下两种方式之一完成此操作: 将sed命令写入文件,确保文件为UTF-8,并将其作为脚本执行: file yourfile应该说UTF-8 Unicode text 。 然后,您可以运行bash yourfile 。 或者,将终端和shell设置更改为UTF-8 printf à | wc -c printf à | wc -c必须说2,而不是1。 locale应在LC_CTYPE行中列出“UTF-8”或“utf8”。 然后,您可以直接从终

...

数据存储 : 在数据库中的所有表和文本列上指定utf8mb4字符集。 这使得MySQL在UTF-8中物理存储和检索本地编码的值。 请注意,如果指定了utf8mb4_* collation(没有任何显式字符集),MySQL将隐式使用utf8mb4编码。 在旧版本的MySQL(<5.5.3)中,您不幸被迫使用简单的utf8 ,它只支持Unicode字符的一个子集。 我希望我在开玩笑。 数据访问 : 在您的应用程序代码(例如PHP)中,无论使用utf8mb4数据库访问方法,都需要将连接字符集设置为utf

...

好吧,顺便说一下,我当然要探索一些编码见解,但最后,解决方案非常简单。 我打算输入这份工作 php myjob.php

这是一个非首发,因为我的服务器上的默认版本太原始,并且不包含函数utf8_encode或mb_convert_encoding。 因此,我现在使用以下命令启动作业: php5.4 myjob.php

......它就像一个魅力。 Well, along the way I certainly got to explore some encoding insights but

...

你不需要这个cron。 一个简单的shell脚本就是你所需要的: #!/bin/sh

while :; do # Loop until the break statement is hit

if task1; then # If task1 is successful

task2 # then run task2

break # and we're done.

else

...

根据这个和这个 Android的sqlite支持只有UTF-8和UTF-16。 这有帮助吗? 亚龙 Came up with a kludgy solution. Basically, I have a blank UTF-16le database file in my assets folder. When I create a new database, I copy this file over (in my SQLiteOpenHelper) and do everything norm

...

问题与油灰配置有关。 它将远程字符集设置为ISO-8859-1。 而且我猜测mysql查询结果显示重音的原因是因为它也使用ISO-8859-1 charset。 要配置putty,只需按照下一个链接: 配置PuTTY以使用UTF-8 要永久更改编码,只需按照此答案进行操作即可在链接的评论中找到,但我不希望您错过它,所以这里是: “为了在Putty中永久更改这些更改,您打开Putty,进行要保存的更改,然后单击Session窗口,单击Saved Sessions下的”Default Settings

...

解决了: 在我的连接脚本中,我改变了这个: $dbh = new PDO("mysql:host=$dbHost;dbname=$dbName;", $dbUser, $dbPass);

$dbh->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8');

对此: $dbh = new PDO("mysql:host=$dbHost;dbname=$dbName;", $dbUser, $dbPass, array(PDO:

...

默认情况下,Hadoop使用UTF-8编码,因此您不必提供此类选项。 我假设您使用Text作为键/值。 根据javadoc :“此类使用标准UTF8编码存储文本” By default Hadoop uses UTF-8 encoding so you don't have to provide such options. I assume you use Text for your keys/values. According to the javadoc: "This class stores

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值