Reply to Re: No mbstring function for finding suitable encoding.

Your name:

Reply:


Posted by Umberto Salsi on 12/11/06 21:39

"Lucas Kruijswijk" <L.B.Kruijswijk@inter.nl.net> wrote:

> So, I want a function:
>
> bool mb_encoding_possible(string str, string to_encoding, string
> from_encoding)
>
> which returns TRUE if mb_convert_encoding is possible, without loss.


/*. boolean .*/ function mb_encoding_possible(
/*. string .*/ $original,
/*. string .*/ $to_encoding,
/*. string .*/ $from_encoding)
/*
Returns TRUE if $original can be converted from $from_encoding
to $to_encoding without loosing neither char.

Very inefficient. It would be useful to return the $converted text
back to the caller, to that it has not to repeat the conversion again.
*/
{
$converted = mb_convert_encoding($original, $to_encoding, $from_encoding);
$original2 = mb_convert_encoding($converted, $from_encoding, $to_encoding);
return $original2 === $original;
}


Some optimizations requires the knowledge of the specific encodings used.
mb_substitute_character() might be useful to mark characters that cannot
be converted. For example, we can choose an ASCII control character
(most encodings do not use them for regular texts) or any other char
that do not appear in the original string, and use this char to mark
characters that cannot be converted. With only one conversion, the
presence of this char in the resulting text would mean we lost something.


Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация