[英]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.