iconv函数有时会给我一个错误:
Notice:
iconv() [function.iconv]:
Detected an incomplete multibyte character in input string in [...]
Run Code Online (Sandbox Code Playgroud)
有没有办法在将数据输入到无线电之前检测到utf-8字符串中存在非法字符?
我在PHP应用程序中有一些代码,当我尝试在生产服务器上使用它时返回null,但它在开发服务器上工作正常.这是代码行:
// use the regex unicode support to separate the UTF-8 characters into an array
preg_match_all( '/./us', $str, $match );
Run Code Online (Sandbox Code Playgroud)
u依赖的标志是什么?我测试了mb_string启用和禁用,它似乎没有影响它.
我得到的错误是
preg_match_all: Compilation failed: unknown option bit(s) set at offset -1
更多信息
这是prodction服务器上的选项之一:
'--with-pcre-regex=/opt/pcre'
这是pcre部分
Picture.png http://img829.imageshack.us/img829/8524/pictureke.png
我相信这是@Wesley所指的注释:
In order process UTF-8 strings, you must build PCRE to include UTF-8
support in the code, and, in addition, you must call pcre_compile()
with the PCRE_UTF8 option flag, or the pattern must start with the
sequence (*UTF8). When …Run Code Online (Sandbox Code Playgroud) 有没有一种简单的方法来检查 JavaScript 中的字符串是否是有效的 UTF-8 序列?
我真的不想以这样的正则表达式结束:
PS:我从外部 API 接收数据,有时(很少但会发生)它返回带有无效 UTF-8 序列的数据。尝试将它们放入 PostgreSQL 会导致相应的错误。
Google+ API的结果已\ufeff附加到每个"内容"结果的末尾(我真的不知道为什么?)
从json结果中删除此unicode字符的最佳方法是什么?它正在生成'?'一些我正在显示的输出.
例:
https://developers.google.com/+/api/latest/activities/get#try-it
Run Code Online (Sandbox Code Playgroud)
输入活动ID
z12pvrsoaxqlw5imi22sdd35jwvkglj5204
Run Code Online (Sandbox Code Playgroud)
然后单击执行,结果将是:
{
.....
"object": {
......
"content": "CONTENT OF GOOGLE PLUS POST HERE \ufeff",
......
Run Code Online (Sandbox Code Playgroud)
显示'?'的示例PHP代码 其中'\ ufeff'是:
<?php
$data = json_decode($result_from_google_plus_api, true);
echo $data['object']['content'];
// outputs "CONTENT OF GOOGLE PLUS POST HERE ?"
echo trim($data['object']['content']);
// outputs "CONTENT OF GOOGLE PLUS POST HERE ?"
Run Code Online (Sandbox Code Playgroud)
或者我是以错误的方式来做这件事的?我应该修理'?' 问题而不是试图删除'\ufeff'?
php ×3
utf-8 ×2
encoding ×1
google-plus ×1
iconv ×1
javascript ×1
json ×1
preg-match ×1
regex ×1