Zeta Components Manual :: Docs For Class ezcMailCharsetConverter
Mail::ezcMailCharsetConverter
Class ezcMailCharsetConverter
Class containing common character set conversion methods.
By calling the static function ezcMailCharsetConverter::setConvertMethod() before doing mail parsing, another callback function can be used for character conversion to UTF-8 in place of the normal iconv() conversion.
The callback function must have this signature:
- public static function function_name( $text, $originalCharset );
where:
- $text = string to convert to UTF-8
- $originalCharset = in what charset is $text
- // specify another function for character set conversion
- // ...code for mail parsing...
where myConverter is (along with some other examples of charset conversion functions which can be used):
- class myConverter
- {
- public static function convertToUTF8IconvIgnore( $text, $originalCharset )
- {
- if ( $originalCharset === 'unknown-8bit' || $originalCharset === 'x-user-defined' )
- {
- $originalCharset = "latin1";
- }
- }
- public static function convertToUTF8IconvTranslit( $text, $originalCharset )
- {
- if ( $originalCharset === 'unknown-8bit' || $originalCharset === 'x-user-defined' )
- {
- $originalCharset = "latin1";
- }
- }
- public static function convertToUTF8Mbstring( $text, $originalCharset )
- {
- }
- }
Developers can choose to use the error suppresion operator ('@') in front of the iconv() calls in the above examples, in order to ignore the notices thrown when processing broken text (issue #8369).
Source for this file: /Mail/src/internal/charset_convert.php
Version: | //autogen// |
Method Summary
public static string |
convertToUTF8(
$text
, $originalCharset
)
Converts the $text with the charset $originalCharset to UTF-8. |
public static string |
convertToUTF8Iconv(
$text
, $originalCharset
)
Converts the $text with the charset $originalCharset to UTF-8. |
public static void |
setConvertMethod(
$method
)
Sets the callback function used for character set conversion to UTF-8. |
Methods
convertToUTF8
Converts the $text with the charset $originalCharset to UTF-8.
It calls the function specified by using the static method setConvertMethod(). By default it calls convertToUTF8Iconv() defined in this class.
Parameters:
Name | Type | Description |
---|---|---|
$text |
string | |
$originalCharset |
string |
convertToUTF8Iconv
Converts the $text with the charset $originalCharset to UTF-8.
In case $originalCharset is 'unknown-8bit' or 'x-user-defined' then it is assumed to be 'latin1' (ISO-8859-1).
Parameters:
Name | Type | Description |
---|---|---|
$text |
string | |
$originalCharset |
string |
setConvertMethod
Sets the callback function used for character set conversion to UTF-8.
Call this method before doing mail parsing if you need a special way of converting the character set to UTF-8.
Parameters:
Name | Type | Description |
---|---|---|
$method |
callback |