@@ -37,7 +37,6 @@ function utf8_strlen($str)
3737 return strlen (utf8_decode ($ str ));
3838}
3939
40-
4140//--------------------------------------------------------------------
4241/**
4342 * UTF-8 aware alternative to strpos
@@ -57,19 +56,17 @@ function utf8_strlen($str)
5756 */
5857function utf8_strpos ($ str , $ needle , $ offset = null )
5958{
60-
6159 if (is_null ($ offset )) {
62-
6360 $ ar = explode ($ needle , $ str , 2 );
6461 if (count ($ ar ) > 1 ) {
6562 return utf8_strlen ($ ar [0 ]);
6663 }
67- return false ;
6864
65+ return false ;
6966 } else {
70-
7167 if (!is_int ($ offset )) {
7268 trigger_error ('utf8_strpos: Offset must be an integer ' , E_USER_ERROR );
69+
7370 return false ;
7471 }
7572
@@ -81,7 +78,6 @@ function utf8_strpos($str, $needle, $offset = null)
8178
8279 return false ;
8380 }
84-
8581}
8682
8783//--------------------------------------------------------------------
@@ -103,23 +99,22 @@ function utf8_strpos($str, $needle, $offset = null)
10399 */
104100function utf8_strrpos ($ str , $ needle , $ offset = null )
105101{
106-
107102 if (is_null ($ offset )) {
108-
109103 $ ar = explode ($ needle , $ str );
110104
111105 if (count ($ ar ) > 1 ) {
112106 // Pop off the end of the string where the last match was made
113107 array_pop ($ ar );
114108 $ str = join ($ needle , $ ar );
109+
115110 return utf8_strlen ($ str );
116111 }
117- return false ;
118112
113+ return false ;
119114 } else {
120-
121115 if (!is_int ($ offset )) {
122116 trigger_error ('utf8_strrpos expects parameter 3 to be long ' , E_USER_WARNING );
117+
123118 return false ;
124119 }
125120
@@ -131,7 +126,6 @@ function utf8_strrpos($str, $needle, $offset = null)
131126
132127 return false ;
133128 }
134-
135129}
136130
137131//--------------------------------------------------------------------
@@ -167,7 +161,6 @@ function utf8_strrpos($str, $needle, $offset = null)
167161 */
168162function utf8_substr ($ str , $ offset , $ length = null )
169163{
170-
171164 // generates E_NOTICE
172165 // for PHP4 objects, but not PHP5 objects
173166 $ str = (string ) $ str ;
@@ -187,14 +180,12 @@ function utf8_substr($str, $offset, $length = null)
187180 // normalise negative offsets (we could use a tail
188181 // anchored pattern, but they are horribly slow!)
189182 if ($ offset < 0 ) {
190-
191183 // see notes
192184 $ strlen = strlen (utf8_decode ($ str ));
193185 $ offset = $ strlen + $ offset ;
194186 if ($ offset < 0 ) {
195187 $ offset = 0 ;
196188 }
197-
198189 }
199190
200191 $ Op = '' ;
@@ -203,7 +194,6 @@ function utf8_substr($str, $offset, $length = null)
203194 // establish a pattern for offset, a
204195 // non-captured group equal in length to offset
205196 if ($ offset > 0 ) {
206-
207197 $ Ox = (int ) ($ offset / 65535 );
208198 $ Oy = $ offset % 65535 ;
209199
@@ -212,22 +202,16 @@ function utf8_substr($str, $offset, $length = null)
212202 }
213203
214204 $ Op = '^(?: ' . $ Op . '.{ ' . $ Oy . '}) ' ;
215-
216205 } else {
217-
218206 // offset == 0; just anchor the pattern
219207 $ Op = '^ ' ;
220-
221208 }
222209
223210 // establish a pattern for length
224211 if (is_null ($ length )) {
225-
226212 // the rest of the string
227213 $ Lp = '(.*)$ ' ;
228-
229214 } else {
230-
231215 if (!isset ($ strlen )) {
232216 // see notes
233217 $ strlen = strlen (utf8_decode ($ str ));
@@ -239,7 +223,6 @@ function utf8_substr($str, $offset, $length = null)
239223 }
240224
241225 if ($ length > 0 ) {
242-
243226 // reduce any length that would
244227 // go passed the end of the string
245228 $ length = min ($ strlen - $ offset , $ length );
@@ -253,10 +236,8 @@ function utf8_substr($str, $offset, $length = null)
253236 $ Lp = '(?:.{65535}){ ' . $ Lx . '} ' ;
254237 }
255238 $ Lp = '( ' . $ Lp . '.{ ' . $ Ly . '}) ' ;
256-
257239 } else {
258240 if ($ length < 0 ) {
259-
260241 if ($ length < ($ offset - $ strlen )) {
261242 return '' ;
262243 }
@@ -271,18 +252,15 @@ function utf8_substr($str, $offset, $length = null)
271252 $ Lp = '(?:.{65535}){ ' . $ Lx . '} ' ;
272253 }
273254 $ Lp = '(.*)(?: ' . $ Lp . '.{ ' . $ Ly . '})$ ' ;
274-
275255 }
276256 }
277-
278257 }
279258
280259 if (!preg_match ('# ' . $ Op . $ Lp . '#us ' , $ str , $ match )) {
281260 return '' ;
282261 }
283262
284263 return $ match [1 ];
285-
286264}
287265
288266//---------------------------------------------------------------
@@ -308,7 +286,6 @@ function utf8_substr($str, $offset, $length = null)
308286 */
309287function utf8_strtolower ($ string )
310288{
311-
312289 static $ UTF8_UPPER_TO_LOWER = null ;
313290
314291 if (is_null ($ UTF8_UPPER_TO_LOWER )) {
@@ -568,7 +545,6 @@ function utf8_strtolower($string)
568545 */
569546function utf8_strtoupper ($ string )
570547{
571-
572548 static $ UTF8_LOWER_TO_UPPER = null ;
573549
574550 if (is_null ($ UTF8_LOWER_TO_UPPER )) {
0 commit comments