Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Remove incomplete multibyte character input string

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3
    • 0
    • 5.24k
    Comment on it

    Hello friends, while importing excel file in MySQL using PHP I was getting following error:

    iconv(): Detected an incomplete multibyte character in an input string

     

    Before proceeding further to solve the error let's first understand what does iconv function is used for?

    iconv function is used to convert a string to requested character encoding

    iconv — Convert string to requested character encoding

     

    Syntax of iconv:

    string iconv ( string $in_charset , string $out_charset , string $str )

     

    Let's have a small example, how does iconv function work:

    <?php
    $text = "This is the Euro symbol ''.";
    echo 'Original : ', $text, PHP_EOL;
    echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;
    echo 'IGNORE   : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;
    echo 'Plain    : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;
    ?>

     

    Output of the above code is:

    Original : This is the Euro symbol ''.
    TRANSLIT : This is the Euro symbol 'EUR'.
    IGNORE   : This is the Euro symbol ''.
    Plain    :
    Notice: iconv(): Detected an illegal character in input string in .\iconv-example.php on line 7


     

    Now come back to the bug that I was getting, please have a look at the following screenshot:

     

    Problem was with the following lines of code:

    $result = iconv('UTF-16LE', $this->_defaultEncoding, $string);

     

    So, I replaced above line of code with the following line and it worked extremely well for me

    $result = iconv('UTF-8', "ISO-8859-1//IGNORE", $string);

    In the above code //IGNORE is specified so that it should not return any special characters.

     

    You can see the following output without any bugs

    Hope this blog will help someone to  sort out the problem.

    Thanks for reading.

    Remove incomplete multibyte character input string

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: