简体   繁体   English

iconv():在输入字符串中检测到非法字符

[英]iconv(): Detected an illegal character in input string

I am using Iconv function to convert string to requested character encoding. 我正在使用Iconv函数将字符串转换为请求的字符编码。 Look On Below Code 看下面的代码

$sms_text =  'A:'f3*'F'; // Output received from SMPP
$result = iconv('UTF-16BE' ,'UTF-8//IGNORE' , $sms_text);
echo 'Ignore: ' .$result;

echo $sms_text = iconv('UTF-16BE' ,'UTF-8' , $sms_text);

$result1 = iconv('UTF-16BE' ,'UTF-8//TRANSLIT' , $sms_text); //line no (53)
echo 'Transilt: '.$result1;

And I received the below Output 我收到以下输出 在此处输入图片说明
If I have a string of dari and pashto Language, then its showing only first word and dont return remaining string after blank space. 如果我有一个dari和pashto语言字符串,则它仅显示第一个单词,并且在空格后不返回其余字符串。 Even //IGNORE gives the same output. 甚至// IGNORE都给出相同的输出。

Should I replace these blank spaces with the help of with some other character so that I can get complete string? 是否应该在其他字符的帮助下替换这些空格,以便获得完整的字符串?

Note: I am passing string received from SMPP(receiver). 注意:我正在传递从SMPP(receiver)接收的字符串。

SMS Sent to SMPP : افغانستان کابل
Outpur Received from SMPP : 'A:'f3*'F
String back converted by iconv : افغانستان 

English string is working well. 英文字符串效果很好。

Thanks in advance. 提前致谢。

You are converting string to UTF-8 charset on this line: 您正在此行上将字符串转换为UTF-8字符集:

echo $sms_text = iconv('UTF-16BE' ,'UTF-8' , $sms_text);

The error appears becouse you are trying to convert it second time. 由于您正尝试第二次转换,因此出现错误。 To resolve this issue you should not update $sms_text variable on mentioned line. 若要解决此问题,您不应在上述行中更新$ sms_text变量。

Here is a code and output that works for me: 这是对我有用的代码和输出:

$sms_text ="فغانستان کابل";

echo "UTF-8 : $sms_text \n";

$sms_text = iconv('UTF-8', 'UTF-16BE', $sms_text);

echo "UTF-16BE : $sms_text \n";

echo 'Ignore: ' . iconv('UTF-16BE' ,'UTF-8//IGNORE' , $sms_text) . "\n";
echo 'Simple: ' . iconv('UTF-16BE' ,'UTF-8' , $sms_text) . "\n";
echo 'Transilt: '. iconv('UTF-16BE' ,'UTF-8//TRANSLIT' , $sms_text) . "\n";

Output: 输出:

UTF-8 : فغانستان کابل 
UTF-16BE : A:'F3*'F
Ignore: فغانستان کابل
Simple: فغانستان کابل
Transilt: فغانستان کابل

As for blank spaces, could you please share the test string? 至于空格,能否请您分享测试字符串?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iconv - 在输入字符串中检测到非法字符 - iconv - Detected an illegal character in input string iconv在输入字符串中检测到非法字符 - iconv Detected an illegal character in input string iconv():在 FPDF 的输入字符串中检测到土耳其语字符的非法字符 - iconv(): Detected an illegal character in input string in FPDF for Turkish characters iconv-注意:iconv()[function.iconv]:在输入字符串中检测到非法字符 - iconv - Notice: iconv() [function.iconv]: Detected an illegal character in input string 带有ascii的iconv //传输触发ErrorException:“ iconv():在输入字符串中检测到非法字符” - iconv with ascii // transit triggers ErrorException: “iconv(): Detected an illegal character in input string” 创建标题Slug时出错注意:iconv():在以下位置的输入字符串中检测到非法字符 - Error while Creating title Slug Notice: iconv(): Detected an illegal character in input string in 使用iconv()检查无效的UTF-8字符:在输入字符串中检测到非法字符 - Using iconv() to check for invalid UTF-8 characters: Detected an illegal character in input string 无法重现“iconv():在输入字符串中检测到非法字符”,但我一直在服务器上 - Can't reproduce “iconv(): Detected an illegal character in input string”, but I keep getting on server iconv():检测到输入字符串中不完整的多字节字符 - iconv(): Detected an incomplete multibyte character in input string 注意:iconv():在Excel_reader.php的输入字符串中检测到不完整的多字节字符 - Notice: iconv(): Detected an incomplete multibyte character in input string in Excel_reader.php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM