iconv

Fixing invalid UTF8 characters

巧了我就是萌 提交于 2019-12-06 15:08:40
I'm importing a txt file in to an sqlite database and then outputting those values in json format using php json_encode fails, complaining about illegal characters. I tracked it down to the two accented characters in the string terrains à bâtir - this string renders fine when I open the file in Sublime but in Textedit the string is shown as terrains ‡ b‚tir Some info about the file and its contents file -i file.txt tells me text/plain; charset=us-ascii mb_detect_encoding() on a valid string tells me it is ASCII mb_detect_encoding() on a invalid string tells me it is UTF-8 hexdump -C file.txt |

关于json_decode乱码及NULL的解决方法

左心房为你撑大大i 提交于 2019-12-06 14:44:41
写接口的同学应该会经常遇到数据格式的转换,这时候必不可少的两个函数就是json_encode()和json_decode()。 这两个函数使用的时候有很多的主要事项,在这里我来说一下json_decode()。 json_decode(): 对JSON 格式的字符串进行解码, 接受一个JSON 格式的字符串并且把它转换为 PHP变量 。 (1)将数据转换成数组之后,打印会显示NUll: 原因之一json_decode只支持utf-8. iconv('gbk','utf-8', $result_string);用iconv函数将写入数据的gbk编码格式转换为要输出的utf-8编码格式,若原本的数据是utf-8格式,则不用此步骤,否则还会出现乱码 注意:使用iconv函数并不是php自带的,需要可以修改php.ini文件,将extension=php_iconv.dll前的";"去掉,同时你要copy你的原php安装文件下的iconv.dll到你的winnt/system32下(如果你的dll指向的是这个目录)。(有可能是php的安装文件???) 原因之二: json字符串必须以双引号包含 str_replace("'", '"', $result_string );//将json数据中的单引替换成双引 原因之三:不能有多余的逗号如:[1,2,] 用正则替换掉,preg_replace

mySQL and PHP encodings

眉间皱痕 提交于 2019-12-06 11:48:45
问题 HI, I have a problem with this query SELECT * FROM table WHERE `name` LIKE '%tést%' the HMTL and the SQL table both have utf-8 encoding but unfortunately there is no mysql_set_charset('utf-8') and I'm NOT able to use it. I've tried with iconv("UTF-8", "ISO-8859-1", $name) but the query matches only test . I want to match all of these : test, tést, tèst, tëst (as it would work with mysql_set_charset ) edit: SET NAMES utf8 is nigher possible ... the database is with utf8 encoding, unfortunately

Iconv::IllegalSequence when using www::mechanize

北城以北 提交于 2019-12-06 09:32:21
问题 I'm trying to do a little bit of webscraping, but the WWW:Mechanize gem doesn't seem to like the encoding and crashes. The post request results in a 302 redirect (which mechanize follows, so far so good) and the resulting page seems to crash it. I googled quite a bit, but nothing came up so far how to solve this. Any of you got an idea? Code: require 'rubygems' require 'mechanize' agent = WWW::Mechanize.new agent.user_agent_alias = 'Mac Safari' answer = agent.post('https://www.budget.de/de

PHP function iconv character encoding from iso-8859-1 to utf-8

扶醉桌前 提交于 2019-12-06 09:25:40
I'm trying to convert a string from iso-8859-1 to utf-8. But when I find these two charachter € and • the function returns a charachter that is a square with two number inside. How can I solve this issue? I think the encoding you are looking for is Windows code page 1252 (Western European). It is not the same as ISO-8859-1 (or 8859-15 for that matter); the characters in the range 0xA0-0xFF match 8859-1, but cp1252 adds an assortment of extra characters in the range 0x80-0x9F where ISO-8859-1 assigns little-used control codes. The confusion comes about because when you serve a page as text/html

Change encoding multiple file with iconv in bash

百般思念 提交于 2019-12-06 04:20:06
问题 I want to change multiple php files encoding with iconv. I use find and exec option (Reference : http://linux.bigresource.com/Ubuntu-Encoding-Conversion-on-Multiple-Files--4fuXvUwbN.html) find . -type f -name '*.php' -print -exec iconv -f euc-kr -t utf-8 {} -o {}.utf8 But the error is occured. find: missing argument to `-exec' I just want to convert all php files in a once time. How can i do this with one statement in a bash? 回答1: You must put either \; or + at the end of the -exec action.

linux笔记

点点圈 提交于 2019-12-06 01:04:53
目录 命令 linux相关命令、配置。 参考文献: 命令 字符编码转换 iconv命令 iconv命令 是用来转换文件的编码方式的 # 语法 iconv -f encoding [-t encoding] [inputfile]... # 选项 -f encoding :把字符从encoding编码开始转换。 -t encoding :把字符转换到encoding编码。 -l :列出已知的编码字符集合 -o file :指定输出文件 -c :忽略输出的非法字符 -s :禁止警告信息,但不是错误信息 --verbose :显示进度信息 -f和-t所能指定的合法字符在-l选项的命令里面都列出来了。 # 列出当前支持的字符编码: iconv -l # 将文件file1转码,转后文件输出到fil2中: iconv file1 -f EUC-JP-MS -t UTF-8 -o file2 rm与管道使用 linux shell: rm 、ls、grep 关于 find grep xargs 命令总结 find、xargs、grep基本用法 ls 与 grep 结合 ls -l | grep ^d # 列出当前路径下的所有文件夹 rm -fr `ls | grep -v "^space.txt$"` # greo正则,ls、rm结合 find、xargs、grep配合使用

PHP ICONV glibc to libiconv on CentOS 5.5

醉酒当歌 提交于 2019-12-05 18:32:56
I'm having a few issues with the PHP function iconv, which I've tracked down the the iconv implementation. As the manual states, "Note that the iconv function on some systems may not work as you expect. In such case, it'd be a good idea to install the GNU libiconv library." http://uk3.php.net/manual/en/intro.iconv.php I've downloaded the libiconv library from http://www.gnu.org/software/libiconv/ and installed it without any problems using: $ ./configure --prefix=/usr/local $ make $ make install My problem now is how to link this installation to PHP? From what i've read I need to recompile PHP

iconv - Detected an illegal character in input string

吃可爱长大的小学妹 提交于 2019-12-05 08:46:20
问题 I don't see anything illegal - any suggestions on what might be the problem? if (strtolower($matches[1]) != 'utf-8') { var_dump($matches[1]); $xml = iconv($matches[1], 'utf-8', $xml); $xml = str_replace('encoding="'.$matches[1].'"', 'encoding="utf-8"', $xml); } Below is my debug/error string(12) "windows-1252" Notice (8): iconv() [http://php.net/function.iconv]: Detected an illegal character in input string [APP/models/sob_form.php, line 16] I've verified that the above code is indeed line 16

Iconv::IllegalSequence when using www::mechanize

ε祈祈猫儿з 提交于 2019-12-04 15:58:59
I'm trying to do a little bit of webscraping, but the WWW:Mechanize gem doesn't seem to like the encoding and crashes. The post request results in a 302 redirect (which mechanize follows, so far so good) and the resulting page seems to crash it. I googled quite a bit, but nothing came up so far how to solve this. Any of you got an idea? Code: require 'rubygems' require 'mechanize' agent = WWW::Mechanize.new agent.user_agent_alias = 'Mac Safari' answer = agent.post('https://www.budget.de/de/reservierung/privatkunden/step1/schnellbuchung', {"Country" => "Deutschland", "Abholstation" => "Aalen",