我使用curl以俄语填写utf-8页面.如果我回复文本它显示良好.然后我使用这样的代码
$dom = new domDocument;
/*** load the html into the object ***/
@$dom->loadHTML($html);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** the table by its tag name ***/
$tables = $dom->getElementsByTagName('table');
/*** get all rows from the table ***/
$rows = $tables->item(0)->getElementsByTagName('tr');
/*** loop over the table rows ***/
for ($i = 0; $i <= 5; $i++)
{
/*** get each column by tag name ***/
$cols = $rows->item($i)->getElementsByTagName('td');
echo $cols->item(2)->nodeValue;
echo '<hr />';
}
Run Code Online (Sandbox Code Playgroud)
$ html包含俄语文本.在它行echo …
我想将字符串从GBK字符集转换为ISO-8859-1。
我尝试使用iconv库,但iconv()始终返回-1,并errno解码为“无效或不完整的多字节或宽字符”。
我该如何实现?
当我运行rspec时,我收到了ruby 1.9.3-p125的以下弃用警告.但是ruby 1.9.2没有弃用的警告.
/gems/ruby-1.9.3-p125@cs/gems/soap4r-1.5.8/lib/xsd/iconvchars
et.rb:9:in `<top (required)>': iconv will be deprecated in the future, use String#encode instead.
/home/ec2-user/.rvm/gems/ruby-1.9.3-p125@cs/gems/hpricot-0.8.2/lib/hpricot/build
er.rb:2:in `require': /gems/ruby-1.9.3-p125@cs/gems/hpricot-0
.8.2/lib/fast_xs.so: undefined symbol: ruby_digitmap - /gems/
ruby-1.9.3-p125@cs/gems/hpricot-0.8.2/lib/fast_xs.so (LoadError)
Run Code Online (Sandbox Code Playgroud)
这可能是什么原因?有人可以帮忙解决这个问题.
我想写一个函数将UTF8字符串转换为UTF16(little-endian).问题是,该iconv函数似乎没有让您事先知道存储输出字符串需要多少字节.
我的解决方案是首先分配2*strlen(utf8),然后iconv在循环中运行,realloc如果需要增加缓冲区的大小:
static int utf8_to_utf16le(char *utf8, char **utf16, int *utf16_len)
{
iconv_t cd;
char *inbuf, *outbuf;
size_t inbytesleft, outbytesleft, nchars, utf16_buf_len;
cd = iconv_open("UTF16LE", "UTF8");
if (cd == (iconv_t)-1) {
printf("!%s: iconv_open failed: %d\n", __func__, errno);
return -1;
}
inbytesleft = strlen(utf8);
if (inbytesleft == 0) {
printf("!%s: empty string\n", __func__);
iconv_close(cd);
return -1;
}
inbuf = utf8;
utf16_buf_len = 2 * inbytesleft; // sufficient in many cases, i.e. if the input …Run Code Online (Sandbox Code Playgroud) 当我尝试通过运行:安装iconv时rvm pkg install iconv,它失败并显示以下错误:
Error running 'autoreconf -is --force',
please read /usr/local/rvm/log/libiconv/autoreconf.log
Configuring libiconv in /usr/local/rvm/src/libiconv-1.13.1.........................
Error running './configure --prefix=/usr/local/rvm/usr --enable-shared',
please read /usr/local/rvm/log/libiconv/configure.log
Compiling libiconv in /usr/local/rvm/src/libiconv-1.13.1..
Error running 'make -j1',
please read /usr/local/rvm/log/libiconv/make.log
Please note that it's required to reinstall all rubies:
rvm reinstall all --force
Run Code Online (Sandbox Code Playgroud)
在日志中,它说:
root@web01:~# cat /usr/local/rvm/log/libiconv/autoreconf.log
configure.ac:134: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2591: _AC_COMPILE_IFELSE is expanded from...
../../lib/autoconf/general.m4:2607: AC_COMPILE_IFELSE is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF …Run Code Online (Sandbox Code Playgroud) 我想将UTF-8字符串转换为CP1255(希伯来语)
我尝试运行以下(我使用detect_encoding,因为我的一些输入不是UTF-8):
foreach($param as $key=>$value){
$newval = iconv(mb_detect_encoding($value),"cp1255",$value);
$querystr .= $key."=".$newval."&";
}
Run Code Online (Sandbox Code Playgroud)
无论如何,结果是所有希伯来字符都返回了漂亮的 符号,而所有其他字符(英语/数字)都是预期的并且希望保持完整.
我该怎么做呢?
我正在尝试将希伯来语中的字符串保存到文件中,同时使用ANSI编码的文件.所有的尝试都失败了我害怕.
所以这是我正在尝试的代码:
$to_file = "????? ?? ????";
$to_file = mb_convert_encoding($to_file, "WINDOWS-1255", "UTF-8");
file_put_contents(dirname(__FILE__) ."/txt/TESTING.txt",$to_file);
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它返回false.
另一种尝试是:
$to_file = iconv("UTF-8", "windows-1252", $to_file);
Run Code Online (Sandbox Code Playgroud)
这将返回一个空字符串.虽然这不起作用,将outpout charset更改为windows-1255 DID工作.所以函数本身可以工作,但由于某种原因它不会转换为1252.
我在之前和之后运行此功能iconv并打印结果
mb_detect_encoding ($to_file);
在iconv编码之前是UTF-8.
后的iconv编码是ASCII(??)
我真的很感激你能给予的任何帮助
我正在尝试在 OSX上构建gnu iconv作为静态库。这不是问题,它可以很好地构建
./configure --enable-static
make clean && make
Run Code Online (Sandbox Code Playgroud)
但是当我在 libiconv.a 上运行 nm 时,我得到以下结果
...
_libiconv
_libiconv_open_
_libiconv_close_
...
Run Code Online (Sandbox Code Playgroud)
这是有问题的,因为我想使用这个库构建 libxml2,它需要以下符号
iconv
iconv_open
iconv_close
Run Code Online (Sandbox Code Playgroud)
查看头文件,似乎这两个符号名称之间的区别在于是否定义了 LIBICONV_PLUG。但是当我运行 make as
make clean && make CPPFLAGS=-DLIBICONV_PLUG
Run Code Online (Sandbox Code Playgroud)
我收到错误是因为有几件事没有定义,例如ICONV_GET_DISCARD_ILSEQ 和ICONV_SET_HOOKS。再次查看头文件,这些仅在未定义 LIBICONV_PLUG 时才定义。
我的问题是,我是否正确使用了 LIBICONV_PLUG?还有其他方法可以使用我需要的符号来获取静态库吗?我应该查看未定义的符号并自己手动定义它们吗?
我试图使用iconvR 中的函数来实现德语单词的正确音译(例如,M\xc3\xb6bel \xe2\x86\x92 Moebel)。
我编写了以下代码(尝试使用英语/德语语言环境):
\niconv("M\xc3\xb6bel", "latin1", "ASCII//TRANSLIT")\n[1] "Mobel"\n\niconv("M\xc3\xb6bel", "UTF-8", "ASCII//TRANSLIT")\n[1] NA\n\niconv("M\xc3\xb6bel", "UTF-8", "ASCII//TRANSLIT", sub ="")\n[1] "Mbel"\n\niconv("M\xc3\xb6bel", "Windows-1252", "ASCII//TRANSLIT")\n[1] "Mobel"\nRun Code Online (Sandbox Code Playgroud)\n然而,这并不能正常工作。这是我的一些测试的输出:
\n#cat + library(ds4psy)\niconv(cat ("M", Umlaut["o"],"bel", sep = ""), "latin1", "ASCII//TRANSLIT")\nM\xc3\xb6belcharacter(0)\nRun Code Online (Sandbox Code Playgroud)\n\n#paste/paste0 + library(ds4psy)\n> iconv(paste ("M", Umlaut["o"],"bel", sep = ""), "latin1", "ASCII//TRANSLIT")\n[1] "MA?bel"\nRun Code Online (Sandbox Code Playgroud)\n为了完整起见,我还尝试了以下stri_trans_general函数stringi:
stri_trans_general("M\xc3\xb6bel", "latin-ascii")\n[1] "Mobel"\nRun Code Online (Sandbox Code Playgroud)\n但是,正如您所看到的,这也不起作用。
\n我不明白的是,为什么该函数在PHPiconv中显然可以正常工作,但在 R 中却无法正常工作:
<?php\n //some German\n $utf8_sentence = \'Wei\xc3\x9f, Goldmann, G\xc3\xb6bel, …Run Code Online (Sandbox Code Playgroud) 我在同一列上使用了几个 mutate 。如何只使用 mutate 一次而不重复列名?
\ndf <- data.frame(\n c1 = c("\xc3\x89l\xc3\xa8ve", "Caf\xc3\xa9", "Ch\xc3\xa2teau", "No\xc3\xabl", "Cr\xc3\xa8me")\n)\n\ndf2 <- df %>% \n mutate(c1 = trimws(c1)) %>%\n mutate(c1 = gsub("\\\\s+", " ", c1)) %>%\n mutate(c1 = gsub("\\"", "", c1)) %>%\n mutate(c1 = iconv(toupper(c1), to = "ASCII//TRANSLIT"))\n \nRun Code Online (Sandbox Code Playgroud)\n