2009/03/24

iconv_substr() gives "Unknown error"

If Unknown error(0), then most likely it is this issue, iconv_substr() gives "Unknown error" when string length = 1" and it was fixed in PHP5.2, if you are still using PHP5.1, here is a workaround for this bug,

/*Reproduce code:
---------------*/
$s = 'x';
$s = iconv_substr($s, 0, 1, 'UTF-8');
var_dump($s);
/*Expected result:
----------------*/
string(1) "x"
/*Actual result:
--------------*/
bool(false)
//and Notice: iconv_substr() [function.iconv-substr.html]: Unknown error
//(0) in ...
/*A workaround:
-------------*/
$s = 'x';
$s .=" "; //add one more empty character
$s = iconv_substr($s, 0, 1, 'UTF-8');

But if you got Unknown error(12), which is what I got in lucene search engine. Then it is a issue in this thread, but don’t know the solution yet.

No comments:

Post a Comment