|
Posted by Lucas Kruijswijk on 12/11/06 22:13
Or add an additional parameter to 'mb_convert_encoding'.
substitute: String, will replace any character that can not be converted.
NULL - Function will return NULL, if there is at least one
character
that can not be converted.
Default is empty string.
Regards,
Lucas
"Umberto Salsi" <salsi@icosaedro.italia> schreef in bericht
news:elkj7f$500$1@nnrp.ngi.it...
> "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
>
Navigation:
[Reply to this message]
|