Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezmbstringmapper.php
Go to the documentation of this file.
1 <?php
24 class eZMBStringMapper
25 {
26 public $RequestedInputCharsetCode;
27 public $InputCharsetCode;
28 public $RequestedOutputCharsetCode;
29 public $OutputCharsetCode;
30 public $Valid;
37 public function __construct( $input_charset_code, $output_charset_code )
38 {
39 $this->RequestedInputCharsetCode = $input_charset_code;
40 $this->InputCharsetCode = eZCharsetInfo::realCharsetCode( $input_charset_code );
41 $this->RequestedOutputCharsetCode = $output_charset_code;
42 $this->OutputCharsetCode = eZCharsetInfo::realCharsetCode( $output_charset_code );
43 $this->Valid = false;
44 if ( !$this->isCharsetSupported( $input_charset_code ) )
45 {
46 eZDebug::writeError( "Input charset $input_charset_code not supported", "eZMBStringMapper" );
47 }
48 else if ( !$this->isCharsetSupported( $output_charset_code ) )
49 {
50 eZDebug::writeError( "Output charset $output_charset_code not supported", "eZMBStringMapper" );
51 }
52 else if ( $this->hasMBStringExtension() )
53 $this->Valid = true;
54 else
55 eZDebug::writeError( "No mbstring functions available", "eZMBStringMapper" );
56 }
57
62 static function &charsetList()
63 {
64 $charsets =& $GLOBALS["eZMBCharsetList"];
65 if ( !is_array( $charsets ) )
66 {
67 $charsetList = array( "ucs-4", "ucs-4be", "ucs-4le", "ucs-2", "ucs-2be", "ucs-2le", "utf-32", "utf-32be", "utf-32le", "utf-16",
68 "utf-16be", "utf-16le", "utf-8", "utf-7", "ascii", "euc-jp", "sjis", "eucjp-win", "sjis-win", "iso-2022-jp", "jis",
69 "iso-8859-1", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8",
70 "iso-8859-9", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "byte2be", "byte2le", "byte4be",
71 "byte4le", "base64", "7bit", "8bit", "utf7-imap" );
72 $charsets = array();
73 foreach ( $charsetList as $charset )
74 {
75 $charsets[$charset] = $charset;
76 }
77 }
78 return $charsets;
79 }
80
95 static function hasMBStringExtension()
96 {
97 return ( function_exists( "mb_convert_encoding" ) and
98 function_exists( "mb_substitute_character" ) and
99 function_exists( "mb_strcut" ) and
100 function_exists( "mb_strlen" ) and
101 function_exists( "mb_strpos" ) and
102 function_exists( "mb_strrpos" ) and
103 function_exists( "mb_strwidth" ) and
104 function_exists( "mb_substr" ) );
105 }
106
107 function inputCharsetCode()
108 {
109 return $this->InputCharsetCode;
110 }
111
112 function outputCharsetCode()
113 {
114 return $this->OutputCharsetCode;
115 }
116
117 function requestedInputCharsetCode()
118 {
119 return $this->RequestedInputCharsetCode;
120 }
121
122 function requestedOutputCharsetCode()
123 {
124 return $this->RequestedOutputCharsetCode;
125 }
126
127 function isCharsetSupported( $charset_code )
128 {
129 $charset_code = eZCharsetInfo::realCharsetCode( $charset_code );
130 return in_array( $charset_code, eZMBStringMapper::charsetList() );
131 }
132
133 function substituteCharacter()
134 {
135 if ( !$this->Valid )
136 return null;
137 return mb_substitute_character();
138 }
139
140 function setSubstituteCharacter( $char )
141 {
142 if ( $this->Valid )
143 mb_substitute_character( $char );
144 }
145
146 function convertString( $str )
147 {
148 if ( !$this->Valid )
149 return $str;
150 return mb_convert_encoding( $str, $this->OutputCharsetCode, $this->InputCharsetCode );
151 }
152
153 function strlen( $str )
154 {
155 return mb_strlen( $str, $this->InputCharsetCode );
156 }
157
158 function strpos( $haystack, $needle, $offset = 0 )
159 {
160 return mb_strpos( $haystack, $needle, $offset, $this->InputCharsetCode );
161 }
162
163 function strrpos( $haystack, $needle )
164 {
165 return mb_strrpos( $haystack, $needle, $this->InputCharsetCode );
166 }
167
168 function substr( $str, $start, $length )
169 {
170 return mb_substr( $str, $start, $length, $this->InputCharsetCode );
171 }
172
181 static function instance( $input_charset_code, $output_charset_code )
182 {
183 $globalsKey = "eZMBStringMapper-$input_charset_code-$output_charset_code";
184
185 if ( !isset( $GLOBALS[$globalsKey] ) ||
186 !( $GLOBALS[$globalsKey] instanceof eZMBStringMapper ) )
187 {
188 $GLOBALS[$globalsKey] = new eZMBStringMapper( $input_charset_code, $output_charset_code );
189 }
190
191 return $GLOBALS[$globalsKey];
192 }
193 }
194
195 ?>
eZCharsetInfo\realCharsetCode
static realCharsetCode( $charsetCode)
Definition: ezcharsetinfo.php:186
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZMBStringMapper
The class eZMBStringMapper does.
Definition: ezmbstringmapper.php:25
eZMBStringMapper\substituteCharacter
substituteCharacter()
Definition: ezmbstringmapper.php:133
eZMBStringMapper\$RequestedInputCharsetCode
$RequestedInputCharsetCode
Definition: ezmbstringmapper.php:26
eZMBStringMapper\substr
substr( $str, $start, $length)
Definition: ezmbstringmapper.php:168
eZMBStringMapper\instance
static instance( $input_charset_code, $output_charset_code)
Definition: ezmbstringmapper.php:181
eZMBStringMapper\__construct
__construct( $input_charset_code, $output_charset_code)
Definition: ezmbstringmapper.php:37
eZMBStringMapper\convertString
convertString( $str)
Definition: ezmbstringmapper.php:146
eZMBStringMapper\inputCharsetCode
inputCharsetCode()
Definition: ezmbstringmapper.php:107
eZMBStringMapper\outputCharsetCode
outputCharsetCode()
Definition: ezmbstringmapper.php:112
eZMBStringMapper\requestedOutputCharsetCode
requestedOutputCharsetCode()
Definition: ezmbstringmapper.php:122
eZMBStringMapper\setSubstituteCharacter
setSubstituteCharacter( $char)
Definition: ezmbstringmapper.php:140
eZMBStringMapper\$Valid
$Valid
Definition: ezmbstringmapper.php:30
eZMBStringMapper\strrpos
strrpos( $haystack, $needle)
Definition: ezmbstringmapper.php:163
eZMBStringMapper\strlen
strlen( $str)
Definition: ezmbstringmapper.php:153
eZMBStringMapper\strpos
strpos( $haystack, $needle, $offset=0)
Definition: ezmbstringmapper.php:158
eZMBStringMapper\requestedInputCharsetCode
requestedInputCharsetCode()
Definition: ezmbstringmapper.php:117
eZMBStringMapper\$OutputCharsetCode
$OutputCharsetCode
Definition: ezmbstringmapper.php:29
eZMBStringMapper\hasMBStringExtension
static hasMBStringExtension()
Definition: ezmbstringmapper.php:95
eZMBStringMapper\isCharsetSupported
isCharsetSupported( $charset_code)
Definition: ezmbstringmapper.php:127
eZMBStringMapper\$InputCharsetCode
$InputCharsetCode
Definition: ezmbstringmapper.php:27
eZMBStringMapper\$RequestedOutputCharsetCode
$RequestedOutputCharsetCode
Definition: ezmbstringmapper.php:28
eZMBStringMapper\charsetList
static & charsetList()
Definition: ezmbstringmapper.php:62
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.