[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.4 | 6 // +---------------------------------------------------------------------------+ 7 // | lib-mbyte.php | 8 // | | 9 // | function collection to handle mutli-byte related issues | 10 // +---------------------------------------------------------------------------+ 11 // | Copyright (C) 2000-2006 by the following authors: | 12 // | | 13 // | Authors: Oliver Spiesshofer - oliver AT spiesshofer DOT com | 14 // +---------------------------------------------------------------------------+ 15 // | | 16 // | This program is free software; you can redistribute it and/or | 17 // | modify it under the terms of the GNU General Public License | 18 // | as published by the Free Software Foundation; either version 2 | 19 // | of the License, or (at your option) any later version. | 20 // | | 21 // | This program is distributed in the hope that it will be useful, | 22 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 23 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 24 // | GNU General Public License for more details. | 25 // | | 26 // | You should have received a copy of the GNU General Public License | 27 // | along with this program; if not, write to the Free Software Foundation, | 28 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 29 // | | 30 // +---------------------------------------------------------------------------+ 31 // 32 // $Id: lib-mbyte.php,v 1.18 2006/10/22 08:38:48 dhaun Exp $ 33 34 if (strpos ($_SERVER['PHP_SELF'], 'lib-mbyte.php') !== false) { 35 die ('This file can not be used on its own!'); 36 } 37 38 // This function is supposed to display only language files in selection drop- 39 // downs that are utf-8 40 function MBYTE_languageList ($charset = 'utf-8') 41 { 42 global $_CONF; 43 44 if ($charset != 'utf-8') { 45 $charset = ''; 46 } 47 48 $language = array (); 49 $fd = opendir ($_CONF['path_language']); 50 51 while (($file = @readdir ($fd)) !== false) { 52 if ((substr ($file, 0, 1) != '.') && preg_match ('/\.php$/i', $file) 53 && is_file ($_CONF['path_language'] . $file) 54 && ((empty ($charset) && (strstr ($file, '_utf-8') === false)) 55 || (($charset == 'utf-8') && strstr ($file, '_utf-8')))) { 56 clearstatcache (); 57 $file = str_replace ('.php', '', $file); 58 $langfile = str_replace ('_utf-8', '', $file); 59 $uscore = strpos ($langfile, '_'); 60 if ($uscore === false) { 61 $lngname = ucfirst ($langfile); 62 } else { 63 $lngname = ucfirst (substr ($langfile, 0, $uscore)); 64 $lngadd = substr ($langfile, $uscore + 1); 65 $lngadd = str_replace ('utf-8', '', $lngadd); 66 $lngadd = str_replace ('_', ', ', $lngadd); 67 $word = explode (' ', $lngadd); 68 $lngadd = ''; 69 foreach ($word as $w) { 70 if (preg_match ('/[0-9]+/', $w)) { 71 $lngadd .= strtoupper ($w) . ' '; 72 } else { 73 $lngadd .= ucfirst ($w) . ' '; 74 } 75 } 76 $lngname .= ' (' . trim ($lngadd) . ')'; 77 } 78 $language[$file] = $lngname; 79 } 80 } 81 asort ($language); 82 83 return $language; 84 } 85 86 // replacement functions for UTF-8 functions 87 function MBYTE_checkEnabled() { 88 static $mb_enabled; 89 if (function_exists( 'mb_substr' )) { 90 $mb_enabled = mb_internal_encoding("UTF-8"); 91 } else { 92 $mb_enabled = false; 93 } 94 return $mb_enabled; 95 } 96 97 98 function MBYTE_strlen($str) { 99 static $mb_enabled; 100 if (!isset($mb_enabled)) { 101 $mb_enabled = MBYTE_checkEnabled(); 102 } 103 if ($mb_enabled) { 104 $result = mb_strlen($str); 105 } else { 106 $result = strlen($str); 107 } 108 return $result; 109 } 110 111 function MBYTE_substr($str, $start, $length = NULL) { 112 static $mb_enabled; 113 if (!isset($mb_enabled)) { 114 $mb_enabled = MBYTE_checkEnabled(); 115 } 116 if ($mb_enabled) { 117 if( $length === NULL ) 118 { 119 $result = mb_substr($str, $start); 120 } else { 121 $result = mb_substr($str, $start, $length); 122 } 123 } else { 124 if( $length === NULL ) 125 { 126 $result = substr($str, $start); 127 } else { 128 $result = substr($str, $start, $length); 129 } 130 } 131 return $result; 132 } 133 134 function MBYTE_strpos($hay, $needle, $offset = NULL) { 135 static $mb_enabled; 136 if (!isset($mb_enabled)) { 137 $mb_enabled = MBYTE_checkEnabled(); 138 } 139 if ($mb_enabled) { 140 $result = mb_strpos($hay, $needle, $offset); 141 } else { 142 $result = strpos($hay, $needle, $offset); 143 } 144 return $result; 145 } 146 147 function MBYTE_strtolower($str) { 148 static $mb_enabled; 149 if (!isset($mb_enabled)) { 150 $mb_enabled = MBYTE_checkEnabled(); 151 } 152 if ($mb_enabled) { 153 $result = mb_strtolower($str); 154 } else { 155 $result = strtolower($str); 156 } 157 return $result; 158 } 159 160 function MBYTE_eregi($pattern, $str, $regs = NULL) { 161 static $mb_enabled; 162 if (!isset($mb_enabled)) { 163 $mb_enabled = MBYTE_checkEnabled(); 164 } 165 if ($mb_enabled) { 166 $result = mb_eregi($pattern, $str, $regs); 167 } else { 168 $result = eregi($pattern, $str, $regs); 169 } 170 return $result; 171 } 172 173 function MBYTE_eregi_replace($pattern, $replace, $str) { 174 static $mb_enabled; 175 if (!isset($mb_enabled)) { 176 $mb_enabled = MBYTE_checkEnabled(); 177 } 178 if ($mb_enabled) { 179 $result = mb_eregi_replace($pattern, $replace, $str); 180 } else { 181 $result = eregi_replace($pattern, $replace, $str); 182 } 183 return $result; 184 } 185 186 /** those are currently not needed in GL, left here if needed later 187 function MBYTE_substr_count($hay, $needle) { 188 static $mb_enabled; 189 if (!isset($mb_enabled)) { 190 $mb_enabled = MBYTE_checkEnabled(); 191 } 192 if ($mb_enabled) { 193 $result = mb_substr_count($hay, $needle, 'utf-8'); 194 } else { 195 $result = substr_count($hay, $needle); 196 } 197 return $result; 198 } 199 200 function MBYTE_strtoupper($str) { 201 static $mb_enabled; 202 if (!isset($mb_enabled)) { 203 $mb_enabled = MBYTE_checkEnabled(); 204 } 205 if ($mb_enabled) { 206 $result = mb_strtoupper($str, 'utf-8'); 207 } else { 208 $result = strtoupper($str); 209 } 210 return $result; 211 } 212 213 function MBYTE_strrpos($hay, $needle, $offset='') { 214 static $mb_enabled; 215 if (!isset($mb_enabled)) { 216 $mb_enabled = MBYTE_checkEnabled(); 217 } 218 if ($mb_enabled) { 219 $result = mb_strrpos($hay, $needle, $offset, 'utf-8'); 220 } else { 221 $result = strrpos($hay, $needle, $offset); 222 } 223 return $result; 224 } 225 226 function MBYTE_mail($to, $subj, $mess, $header = NULL, $param = NULL) { 227 static $mb_enabled; 228 if (!isset($mb_enabled)) { 229 $mb_enabled = MBYTE_checkEnabled(); 230 } 231 if ($mb_enabled) { 232 if (mb_language('uni')) { 233 $result = mb_send_mail($to, $subj, $mess, $header, $param); 234 } else { 235 $result = false; 236 } 237 } else { 238 $result = mail($to, $subj, $mess, $header, $param); 239 } 240 return $result; 241 } 242 243 */ 244 245 246 /** 247 mb_decode_mimeheader -- Decode string in MIME header field 248 mb_decode_numericentity -- Decode HTML numeric string reference to character 249 mb_encode_mimeheader -- Encode string for MIME header 250 mb_encode_numericentity -- Encode character to HTML numeric string reference 251 mb_ereg_match -- Regular expression match for multibyte string 252 mb_ereg_search_getpos -- Returns start point for next regular expression match 253 mb_ereg_search_getregs -- Retrieve the result from the last multibyte regular expression match 254 mb_ereg_search_init -- Setup string and regular expression for multibyte regular expression match 255 mb_ereg_search_pos -- Return position and length of matched part of multibyte regular expression for predefined multibyte string 256 mb_ereg_search_regs -- Returns the matched part of multibyte regular expression 257 mb_ereg_search_setpos -- Set start point of next regular expression match 258 mb_ereg_search -- Multibyte regular expression match for predefined multibyte string 259 mb_parse_str -- Parse GET/POST/COOKIE data and set global variable 260 mb_split -- Split multibyte string using regular expression 261 mb_strcut -- Get part of string 262 mb_strimwidth -- Get truncated string with specified width 263 mb_strrpos -- Find position of last occurrence of a string in a string 264 mb_strwidth -- Return width of string 265 mb_substitute_character -- Set/Get substitution character 266 mb_substr_count -- Count the number of substring occurrences 267 */ 268 269 270 271 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |