iconv vs. mbstring - invalid character detection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

iconv vs. mbstring - invalid character detection

Post by newmember »

Hi

i'm converting utf-8 string to iso-8859-5 string and save it in database.( if there is even one invalid char, futher processing aborted and user reported that some field contain invalid chars.)

iconv() generates E_NOTICE error when it sees invalid character so i can trap it with custom error handler.

then i looked into mb_convert_encoding() function.
the problem with it that it does not let you know if there are any invalid chars in the string.
the only workaround that i thought about is to use mb_substitute_character() to set substitute char to some special char and after call to mb_convert_encoding() , search the converted string for that char.. but this solution looks somewhat clumsy...


can anyone offer another way?
thanks.
Post Reply