Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

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