@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | // securité |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // se faciliter la lecture du charset |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 43 | 43 | **/ |
| 44 | 44 | function load_charset($charset = 'AUTO') { |
| 45 | - if ($charset == 'AUTO') { |
|
| 46 | - $charset = $GLOBALS['meta']['charset']; |
|
| 47 | - } |
|
| 48 | - $charset = trim(strtolower($charset)); |
|
| 49 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | - return $charset; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($charset == 'utf-8') { |
|
| 54 | - $GLOBALS['CHARSET'][$charset] = array(); |
|
| 55 | - |
|
| 56 | - return $charset; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Quelques synonymes |
|
| 60 | - if ($charset == '') { |
|
| 61 | - $charset = 'iso-8859-1'; |
|
| 62 | - } else { |
|
| 63 | - if ($charset == 'windows-1250') { |
|
| 64 | - $charset = 'cp1250'; |
|
| 65 | - } else { |
|
| 66 | - if ($charset == 'windows-1251') { |
|
| 67 | - $charset = 'cp1251'; |
|
| 68 | - } else { |
|
| 69 | - if ($charset == 'windows-1256') { |
|
| 70 | - $charset = 'cp1256'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | - return $charset; |
|
| 78 | - } else { |
|
| 79 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | - $GLOBALS['CHARSET'][$charset] = array(); |
|
| 81 | - |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 45 | + if ($charset == 'AUTO') { |
|
| 46 | + $charset = $GLOBALS['meta']['charset']; |
|
| 47 | + } |
|
| 48 | + $charset = trim(strtolower($charset)); |
|
| 49 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | + return $charset; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($charset == 'utf-8') { |
|
| 54 | + $GLOBALS['CHARSET'][$charset] = array(); |
|
| 55 | + |
|
| 56 | + return $charset; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Quelques synonymes |
|
| 60 | + if ($charset == '') { |
|
| 61 | + $charset = 'iso-8859-1'; |
|
| 62 | + } else { |
|
| 63 | + if ($charset == 'windows-1250') { |
|
| 64 | + $charset = 'cp1250'; |
|
| 65 | + } else { |
|
| 66 | + if ($charset == 'windows-1251') { |
|
| 67 | + $charset = 'cp1251'; |
|
| 68 | + } else { |
|
| 69 | + if ($charset == 'windows-1256') { |
|
| 70 | + $charset = 'cp1256'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | + return $charset; |
|
| 78 | + } else { |
|
| 79 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | + $GLOBALS['CHARSET'][$charset] = array(); |
|
| 81 | + |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,30 +91,30 @@ discard block |
||
| 91 | 91 | * true si toutes les fonctions mb nécessaires sont présentes |
| 92 | 92 | **/ |
| 93 | 93 | function init_mb_string() { |
| 94 | - static $mb; |
|
| 95 | - |
|
| 96 | - // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | - // et que le charset interne est connu de mb_string |
|
| 98 | - if (!$mb) { |
|
| 99 | - if (function_exists('mb_internal_encoding') |
|
| 100 | - and function_exists('mb_detect_order') |
|
| 101 | - and function_exists('mb_substr') |
|
| 102 | - and function_exists('mb_strlen') |
|
| 103 | - and function_exists('mb_strtolower') |
|
| 104 | - and function_exists('mb_strtoupper') |
|
| 105 | - and function_exists('mb_encode_mimeheader') |
|
| 106 | - and function_exists('mb_encode_numericentity') |
|
| 107 | - and function_exists('mb_decode_numericentity') |
|
| 108 | - and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 109 | - ) { |
|
| 110 | - mb_internal_encoding('utf-8'); |
|
| 111 | - $mb = 1; |
|
| 112 | - } else { |
|
| 113 | - $mb = -1; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return ($mb == 1); |
|
| 94 | + static $mb; |
|
| 95 | + |
|
| 96 | + // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | + // et que le charset interne est connu de mb_string |
|
| 98 | + if (!$mb) { |
|
| 99 | + if (function_exists('mb_internal_encoding') |
|
| 100 | + and function_exists('mb_detect_order') |
|
| 101 | + and function_exists('mb_substr') |
|
| 102 | + and function_exists('mb_strlen') |
|
| 103 | + and function_exists('mb_strtolower') |
|
| 104 | + and function_exists('mb_strtoupper') |
|
| 105 | + and function_exists('mb_encode_mimeheader') |
|
| 106 | + and function_exists('mb_encode_numericentity') |
|
| 107 | + and function_exists('mb_decode_numericentity') |
|
| 108 | + and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 109 | + ) { |
|
| 110 | + mb_internal_encoding('utf-8'); |
|
| 111 | + $mb = 1; |
|
| 112 | + } else { |
|
| 113 | + $mb = -1; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return ($mb == 1); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -129,21 +129,21 @@ discard block |
||
| 129 | 129 | * true si iconv fonctionne correctement |
| 130 | 130 | **/ |
| 131 | 131 | function test_iconv() { |
| 132 | - static $iconv_ok; |
|
| 133 | - |
|
| 134 | - if (!$iconv_ok) { |
|
| 135 | - if (!function_exists('iconv')) { |
|
| 136 | - $iconv_ok = -1; |
|
| 137 | - } else { |
|
| 138 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 139 | - $iconv_ok = 1; |
|
| 140 | - } else { |
|
| 141 | - $iconv_ok = -1; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return ($iconv_ok == 1); |
|
| 132 | + static $iconv_ok; |
|
| 133 | + |
|
| 134 | + if (!$iconv_ok) { |
|
| 135 | + if (!function_exists('iconv')) { |
|
| 136 | + $iconv_ok = -1; |
|
| 137 | + } else { |
|
| 138 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 139 | + $iconv_ok = 1; |
|
| 140 | + } else { |
|
| 141 | + $iconv_ok = -1; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return ($iconv_ok == 1); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
@@ -156,18 +156,18 @@ discard block |
||
| 156 | 156 | * true si PCRE supporte l'UTF-8 correctement |
| 157 | 157 | **/ |
| 158 | 158 | function test_pcre_unicode() { |
| 159 | - static $pcre_ok = 0; |
|
| 160 | - |
|
| 161 | - if (!$pcre_ok) { |
|
| 162 | - $s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " "; |
|
| 163 | - if (preg_match(',\W...\W,u', $s)) { |
|
| 164 | - $pcre_ok = 1; |
|
| 165 | - } else { |
|
| 166 | - $pcre_ok = -1; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return $pcre_ok == 1; |
|
| 159 | + static $pcre_ok = 0; |
|
| 160 | + |
|
| 161 | + if (!$pcre_ok) { |
|
| 162 | + $s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " "; |
|
| 163 | + if (preg_match(',\W...\W,u', $s)) { |
|
| 164 | + $pcre_ok = 1; |
|
| 165 | + } else { |
|
| 166 | + $pcre_ok = -1; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return $pcre_ok == 1; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -183,22 +183,22 @@ discard block |
||
| 183 | 183 | * Plage de caractères |
| 184 | 184 | **/ |
| 185 | 185 | function pcre_lettres_unicode() { |
| 186 | - static $plage_unicode; |
|
| 187 | - |
|
| 188 | - if (!$plage_unicode) { |
|
| 189 | - if (test_pcre_unicode()) { |
|
| 190 | - // cf. http://www.unicode.org/charts/ |
|
| 191 | - $plage_unicode = '\w' // iso-latin |
|
| 192 | - . '\x{100}-\x{24f}' // europeen etendu |
|
| 193 | - . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 194 | - ; |
|
| 195 | - } else { |
|
| 196 | - // fallback a trois sous |
|
| 197 | - $plage_unicode = '\w'; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $plage_unicode; |
|
| 186 | + static $plage_unicode; |
|
| 187 | + |
|
| 188 | + if (!$plage_unicode) { |
|
| 189 | + if (test_pcre_unicode()) { |
|
| 190 | + // cf. http://www.unicode.org/charts/ |
|
| 191 | + $plage_unicode = '\w' // iso-latin |
|
| 192 | + . '\x{100}-\x{24f}' // europeen etendu |
|
| 193 | + . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 194 | + ; |
|
| 195 | + } else { |
|
| 196 | + // fallback a trois sous |
|
| 197 | + $plage_unicode = '\w'; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $plage_unicode; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * Plage de caractères |
| 217 | 217 | **/ |
| 218 | 218 | function plage_punct_unicode() { |
| 219 | - return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 219 | + return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -236,72 +236,72 @@ discard block |
||
| 236 | 236 | * Texte corrigé |
| 237 | 237 | **/ |
| 238 | 238 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 239 | - static $trans; |
|
| 240 | - |
|
| 241 | - if (is_array($texte)) { |
|
| 242 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if ($charset == 'AUTO') { |
|
| 246 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 247 | - } |
|
| 248 | - if ($charset == 'utf-8') { |
|
| 249 | - $p = chr(194); |
|
| 250 | - if (strpos($texte, $p) == false) { |
|
| 251 | - return $texte; |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - if ($charset == 'iso-8859-1') { |
|
| 255 | - $p = ''; |
|
| 256 | - } else { |
|
| 257 | - return $texte; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 262 | - $trans[$charset][$charset_cible] = array( |
|
| 263 | - $p . chr(128) => "€", |
|
| 264 | - $p . chr(129) => ' ', # pas affecte |
|
| 265 | - $p . chr(130) => "‚", |
|
| 266 | - $p . chr(131) => "ƒ", |
|
| 267 | - $p . chr(132) => "„", |
|
| 268 | - $p . chr(133) => "…", |
|
| 269 | - $p . chr(134) => "†", |
|
| 270 | - $p . chr(135) => "‡", |
|
| 271 | - $p . chr(136) => "ˆ", |
|
| 272 | - $p . chr(137) => "‰", |
|
| 273 | - $p . chr(138) => "Š", |
|
| 274 | - $p . chr(139) => "‹", |
|
| 275 | - $p . chr(140) => "Œ", |
|
| 276 | - $p . chr(141) => ' ', # pas affecte |
|
| 277 | - $p . chr(142) => "Ž", |
|
| 278 | - $p . chr(143) => ' ', # pas affecte |
|
| 279 | - $p . chr(144) => ' ', # pas affecte |
|
| 280 | - $p . chr(145) => "‘", |
|
| 281 | - $p . chr(146) => "’", |
|
| 282 | - $p . chr(147) => "“", |
|
| 283 | - $p . chr(148) => "”", |
|
| 284 | - $p . chr(149) => "•", |
|
| 285 | - $p . chr(150) => "–", |
|
| 286 | - $p . chr(151) => "—", |
|
| 287 | - $p . chr(152) => "˜", |
|
| 288 | - $p . chr(153) => "™", |
|
| 289 | - $p . chr(154) => "š", |
|
| 290 | - $p . chr(155) => "›", |
|
| 291 | - $p . chr(156) => "œ", |
|
| 292 | - $p . chr(157) => ' ', # pas affecte |
|
| 293 | - $p . chr(158) => "ž", |
|
| 294 | - $p . chr(159) => "Ÿ", |
|
| 295 | - ); |
|
| 296 | - if ($charset_cible != 'unicode') { |
|
| 297 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 298 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - return @str_replace(array_keys($trans[$charset][$charset_cible]), |
|
| 304 | - array_values($trans[$charset][$charset_cible]), $texte); |
|
| 239 | + static $trans; |
|
| 240 | + |
|
| 241 | + if (is_array($texte)) { |
|
| 242 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if ($charset == 'AUTO') { |
|
| 246 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 247 | + } |
|
| 248 | + if ($charset == 'utf-8') { |
|
| 249 | + $p = chr(194); |
|
| 250 | + if (strpos($texte, $p) == false) { |
|
| 251 | + return $texte; |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + if ($charset == 'iso-8859-1') { |
|
| 255 | + $p = ''; |
|
| 256 | + } else { |
|
| 257 | + return $texte; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 262 | + $trans[$charset][$charset_cible] = array( |
|
| 263 | + $p . chr(128) => "€", |
|
| 264 | + $p . chr(129) => ' ', # pas affecte |
|
| 265 | + $p . chr(130) => "‚", |
|
| 266 | + $p . chr(131) => "ƒ", |
|
| 267 | + $p . chr(132) => "„", |
|
| 268 | + $p . chr(133) => "…", |
|
| 269 | + $p . chr(134) => "†", |
|
| 270 | + $p . chr(135) => "‡", |
|
| 271 | + $p . chr(136) => "ˆ", |
|
| 272 | + $p . chr(137) => "‰", |
|
| 273 | + $p . chr(138) => "Š", |
|
| 274 | + $p . chr(139) => "‹", |
|
| 275 | + $p . chr(140) => "Œ", |
|
| 276 | + $p . chr(141) => ' ', # pas affecte |
|
| 277 | + $p . chr(142) => "Ž", |
|
| 278 | + $p . chr(143) => ' ', # pas affecte |
|
| 279 | + $p . chr(144) => ' ', # pas affecte |
|
| 280 | + $p . chr(145) => "‘", |
|
| 281 | + $p . chr(146) => "’", |
|
| 282 | + $p . chr(147) => "“", |
|
| 283 | + $p . chr(148) => "”", |
|
| 284 | + $p . chr(149) => "•", |
|
| 285 | + $p . chr(150) => "–", |
|
| 286 | + $p . chr(151) => "—", |
|
| 287 | + $p . chr(152) => "˜", |
|
| 288 | + $p . chr(153) => "™", |
|
| 289 | + $p . chr(154) => "š", |
|
| 290 | + $p . chr(155) => "›", |
|
| 291 | + $p . chr(156) => "œ", |
|
| 292 | + $p . chr(157) => ' ', # pas affecte |
|
| 293 | + $p . chr(158) => "ž", |
|
| 294 | + $p . chr(159) => "Ÿ", |
|
| 295 | + ); |
|
| 296 | + if ($charset_cible != 'unicode') { |
|
| 297 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 298 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + return @str_replace(array_keys($trans[$charset][$charset_cible]), |
|
| 304 | + array_values($trans[$charset][$charset_cible]), $texte); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -318,24 +318,24 @@ discard block |
||
| 318 | 318 | * Texte converti |
| 319 | 319 | **/ |
| 320 | 320 | function html2unicode($texte, $secure = false) { |
| 321 | - if (strpos($texte, '&') === false) { |
|
| 322 | - return $texte; |
|
| 323 | - } |
|
| 324 | - static $trans = array(); |
|
| 325 | - if (!$trans) { |
|
| 326 | - load_charset('html'); |
|
| 327 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 328 | - $trans["&$key;"] = $val; |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - if ($secure) { |
|
| 333 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 334 | - } else { |
|
| 335 | - return str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), |
|
| 336 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 337 | - ); |
|
| 338 | - } |
|
| 321 | + if (strpos($texte, '&') === false) { |
|
| 322 | + return $texte; |
|
| 323 | + } |
|
| 324 | + static $trans = array(); |
|
| 325 | + if (!$trans) { |
|
| 326 | + load_charset('html'); |
|
| 327 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 328 | + $trans["&$key;"] = $val; |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + if ($secure) { |
|
| 333 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 334 | + } else { |
|
| 335 | + return str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), |
|
| 336 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 337 | + ); |
|
| 338 | + } |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
@@ -350,16 +350,16 @@ discard block |
||
| 350 | 350 | * Texte converti |
| 351 | 351 | **/ |
| 352 | 352 | function mathml2unicode($texte) { |
| 353 | - static $trans; |
|
| 354 | - if (!$trans) { |
|
| 355 | - load_charset('mathml'); |
|
| 353 | + static $trans; |
|
| 354 | + if (!$trans) { |
|
| 355 | + load_charset('mathml'); |
|
| 356 | 356 | |
| 357 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 358 | - $trans["&$key;"] = $val; |
|
| 359 | - } |
|
| 360 | - } |
|
| 357 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 358 | + $trans["&$key;"] = $val; |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 362 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | |
@@ -381,69 +381,69 @@ discard block |
||
| 381 | 381 | * Texte converti en unicode |
| 382 | 382 | **/ |
| 383 | 383 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 384 | - static $trans; |
|
| 385 | - |
|
| 386 | - if ($charset == 'AUTO') { |
|
| 387 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - if ($charset == '') { |
|
| 391 | - $charset = 'iso-8859-1'; |
|
| 392 | - } |
|
| 393 | - $charset = strtolower($charset); |
|
| 394 | - |
|
| 395 | - switch ($charset) { |
|
| 396 | - case 'utf-8': |
|
| 397 | - case 'utf8': |
|
| 398 | - return utf_8_to_unicode($texte); |
|
| 399 | - |
|
| 400 | - case 'iso-8859-1': |
|
| 401 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 402 | - // pas de break; ici, on suit sur default: |
|
| 403 | - |
|
| 404 | - default: |
|
| 405 | - // mbstring presente ? |
|
| 406 | - if (init_mb_string()) { |
|
| 407 | - if ($order = mb_detect_order() # mb_string connait-il $charset? |
|
| 408 | - and mb_detect_order($charset) |
|
| 409 | - ) { |
|
| 410 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 411 | - if ($s && $s != $texte) { |
|
| 412 | - return utf_8_to_unicode($s); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - mb_detect_order($order); # remettre comme precedemment |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 419 | - if (!isset($trans[$charset])) { |
|
| 420 | - if ($cset = load_charset($charset) |
|
| 421 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 422 | - ) { |
|
| 423 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 424 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - if (count($trans[$charset])) { |
|
| 429 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 433 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 434 | - // surtout en utf-8, gere ci-dessus) |
|
| 435 | - if (test_iconv()) { |
|
| 436 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 437 | - if ($s) { |
|
| 438 | - return utf_32_to_unicode($s); |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - // Au pire ne rien faire |
|
| 443 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 444 | - |
|
| 445 | - return $texte; |
|
| 446 | - } |
|
| 384 | + static $trans; |
|
| 385 | + |
|
| 386 | + if ($charset == 'AUTO') { |
|
| 387 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + if ($charset == '') { |
|
| 391 | + $charset = 'iso-8859-1'; |
|
| 392 | + } |
|
| 393 | + $charset = strtolower($charset); |
|
| 394 | + |
|
| 395 | + switch ($charset) { |
|
| 396 | + case 'utf-8': |
|
| 397 | + case 'utf8': |
|
| 398 | + return utf_8_to_unicode($texte); |
|
| 399 | + |
|
| 400 | + case 'iso-8859-1': |
|
| 401 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 402 | + // pas de break; ici, on suit sur default: |
|
| 403 | + |
|
| 404 | + default: |
|
| 405 | + // mbstring presente ? |
|
| 406 | + if (init_mb_string()) { |
|
| 407 | + if ($order = mb_detect_order() # mb_string connait-il $charset? |
|
| 408 | + and mb_detect_order($charset) |
|
| 409 | + ) { |
|
| 410 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 411 | + if ($s && $s != $texte) { |
|
| 412 | + return utf_8_to_unicode($s); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + mb_detect_order($order); # remettre comme precedemment |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 419 | + if (!isset($trans[$charset])) { |
|
| 420 | + if ($cset = load_charset($charset) |
|
| 421 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 422 | + ) { |
|
| 423 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 424 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + if (count($trans[$charset])) { |
|
| 429 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 433 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 434 | + // surtout en utf-8, gere ci-dessus) |
|
| 435 | + if (test_iconv()) { |
|
| 436 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 437 | + if ($s) { |
|
| 438 | + return utf_32_to_unicode($s); |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + // Au pire ne rien faire |
|
| 443 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 444 | + |
|
| 445 | + return $texte; |
|
| 446 | + } |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | |
@@ -462,44 +462,44 @@ discard block |
||
| 462 | 462 | * Texte transformé dans le charset souhaité |
| 463 | 463 | **/ |
| 464 | 464 | function unicode2charset($texte, $charset = 'AUTO') { |
| 465 | - static $CHARSET_REVERSE; |
|
| 466 | - static $trans = array(); |
|
| 467 | - |
|
| 468 | - if ($charset == 'AUTO') { |
|
| 469 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - switch ($charset) { |
|
| 473 | - case 'utf-8': |
|
| 474 | - return unicode_to_utf_8($texte); |
|
| 475 | - break; |
|
| 476 | - |
|
| 477 | - default: |
|
| 478 | - $charset = load_charset($charset); |
|
| 479 | - |
|
| 480 | - if (!is_array($CHARSET_REVERSE[$charset])) { |
|
| 481 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if (!isset($trans[$charset])) { |
|
| 485 | - $trans[$charset] = array(); |
|
| 486 | - $t = &$trans[$charset]; |
|
| 487 | - for ($e = 128; $e < 255; $e++) { |
|
| 488 | - $h = dechex($e); |
|
| 489 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 490 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 491 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 492 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 493 | - } else { |
|
| 494 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 495 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 500 | - |
|
| 501 | - return $texte; |
|
| 502 | - } |
|
| 465 | + static $CHARSET_REVERSE; |
|
| 466 | + static $trans = array(); |
|
| 467 | + |
|
| 468 | + if ($charset == 'AUTO') { |
|
| 469 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + switch ($charset) { |
|
| 473 | + case 'utf-8': |
|
| 474 | + return unicode_to_utf_8($texte); |
|
| 475 | + break; |
|
| 476 | + |
|
| 477 | + default: |
|
| 478 | + $charset = load_charset($charset); |
|
| 479 | + |
|
| 480 | + if (!is_array($CHARSET_REVERSE[$charset])) { |
|
| 481 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if (!isset($trans[$charset])) { |
|
| 485 | + $trans[$charset] = array(); |
|
| 486 | + $t = &$trans[$charset]; |
|
| 487 | + for ($e = 128; $e < 255; $e++) { |
|
| 488 | + $h = dechex($e); |
|
| 489 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 490 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 491 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 492 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 493 | + } else { |
|
| 494 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 495 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 500 | + |
|
| 501 | + return $texte; |
|
| 502 | + } |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | |
@@ -517,37 +517,37 @@ discard block |
||
| 517 | 517 | * Texte transformé dans le charset site |
| 518 | 518 | **/ |
| 519 | 519 | function importer_charset($texte, $charset = 'AUTO') { |
| 520 | - static $trans = array(); |
|
| 521 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 522 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 523 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 524 | - if (init_mb_string()) { |
|
| 525 | - if ($order = mb_detect_order() # mb_string connait-il $charset? |
|
| 526 | - and mb_detect_order($charset) |
|
| 527 | - ) { |
|
| 528 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 529 | - } |
|
| 530 | - mb_detect_order($order); # remettre comme precedemment |
|
| 531 | - return $s; |
|
| 532 | - } |
|
| 533 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 534 | - if (!isset($trans[$charset])) { |
|
| 535 | - if ($cset = load_charset($charset) |
|
| 536 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 537 | - ) { |
|
| 538 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 539 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - if (count($trans[$charset])) { |
|
| 544 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return $texte; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 520 | + static $trans = array(); |
|
| 521 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 522 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 523 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 524 | + if (init_mb_string()) { |
|
| 525 | + if ($order = mb_detect_order() # mb_string connait-il $charset? |
|
| 526 | + and mb_detect_order($charset) |
|
| 527 | + ) { |
|
| 528 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 529 | + } |
|
| 530 | + mb_detect_order($order); # remettre comme precedemment |
|
| 531 | + return $s; |
|
| 532 | + } |
|
| 533 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 534 | + if (!isset($trans[$charset])) { |
|
| 535 | + if ($cset = load_charset($charset) |
|
| 536 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 537 | + ) { |
|
| 538 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 539 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + if (count($trans[$charset])) { |
|
| 544 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return $texte; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -563,92 +563,92 @@ discard block |
||
| 563 | 563 | **/ |
| 564 | 564 | function utf_8_to_unicode($source) { |
| 565 | 565 | |
| 566 | - // mb_string : methode rapide |
|
| 567 | - if (init_mb_string()) { |
|
| 568 | - $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF); |
|
| 569 | - |
|
| 570 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // Sinon methode pas a pas |
|
| 574 | - static $decrement; |
|
| 575 | - static $shift; |
|
| 576 | - |
|
| 577 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 578 | - if (!is_array($decrement)) { |
|
| 579 | - // array used to figure what number to decrement from character order value |
|
| 580 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 581 | - $decrement[4] = 240; |
|
| 582 | - $decrement[3] = 224; |
|
| 583 | - $decrement[2] = 192; |
|
| 584 | - $decrement[1] = 0; |
|
| 585 | - // the number of bits to shift each charNum by |
|
| 586 | - $shift[1][0] = 0; |
|
| 587 | - $shift[2][0] = 6; |
|
| 588 | - $shift[2][1] = 0; |
|
| 589 | - $shift[3][0] = 12; |
|
| 590 | - $shift[3][1] = 6; |
|
| 591 | - $shift[3][2] = 0; |
|
| 592 | - $shift[4][0] = 18; |
|
| 593 | - $shift[4][1] = 12; |
|
| 594 | - $shift[4][2] = 6; |
|
| 595 | - $shift[4][3] = 0; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - $pos = 0; |
|
| 599 | - $len = strlen($source); |
|
| 600 | - $encodedString = ''; |
|
| 601 | - while ($pos < $len) { |
|
| 602 | - $char = ''; |
|
| 603 | - $ischar = false; |
|
| 604 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 605 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 606 | - // 4 chars representing one unicode character |
|
| 607 | - $thisLetter = substr($source, $pos, 4); |
|
| 608 | - $pos += 4; |
|
| 609 | - } else { |
|
| 610 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 611 | - // 3 chars representing one unicode character |
|
| 612 | - $thisLetter = substr($source, $pos, 3); |
|
| 613 | - $pos += 3; |
|
| 614 | - } else { |
|
| 615 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 616 | - // 2 chars representing one unicode character |
|
| 617 | - $thisLetter = substr($source, $pos, 2); |
|
| 618 | - $pos += 2; |
|
| 619 | - } else { |
|
| 620 | - // 1 char (lower ascii) |
|
| 621 | - $thisLetter = substr($source, $pos, 1); |
|
| 622 | - $pos += 1; |
|
| 623 | - $char = $thisLetter; |
|
| 624 | - $ischar = true; |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if ($ischar) { |
|
| 630 | - $encodedString .= $char; |
|
| 631 | - } else { // process the string representing the letter to a unicode entity |
|
| 632 | - $thisLen = strlen($thisLetter); |
|
| 633 | - $thisPos = 0; |
|
| 634 | - $decimalCode = 0; |
|
| 635 | - while ($thisPos < $thisLen) { |
|
| 636 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 637 | - if ($thisPos == 0) { |
|
| 638 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 639 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 640 | - } else { |
|
| 641 | - $charNum = intval($thisCharOrd - 128); |
|
| 642 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 643 | - } |
|
| 644 | - $thisPos++; |
|
| 645 | - } |
|
| 646 | - $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 647 | - $encodedString .= $encodedLetter; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $encodedString; |
|
| 566 | + // mb_string : methode rapide |
|
| 567 | + if (init_mb_string()) { |
|
| 568 | + $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF); |
|
| 569 | + |
|
| 570 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Sinon methode pas a pas |
|
| 574 | + static $decrement; |
|
| 575 | + static $shift; |
|
| 576 | + |
|
| 577 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 578 | + if (!is_array($decrement)) { |
|
| 579 | + // array used to figure what number to decrement from character order value |
|
| 580 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 581 | + $decrement[4] = 240; |
|
| 582 | + $decrement[3] = 224; |
|
| 583 | + $decrement[2] = 192; |
|
| 584 | + $decrement[1] = 0; |
|
| 585 | + // the number of bits to shift each charNum by |
|
| 586 | + $shift[1][0] = 0; |
|
| 587 | + $shift[2][0] = 6; |
|
| 588 | + $shift[2][1] = 0; |
|
| 589 | + $shift[3][0] = 12; |
|
| 590 | + $shift[3][1] = 6; |
|
| 591 | + $shift[3][2] = 0; |
|
| 592 | + $shift[4][0] = 18; |
|
| 593 | + $shift[4][1] = 12; |
|
| 594 | + $shift[4][2] = 6; |
|
| 595 | + $shift[4][3] = 0; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + $pos = 0; |
|
| 599 | + $len = strlen($source); |
|
| 600 | + $encodedString = ''; |
|
| 601 | + while ($pos < $len) { |
|
| 602 | + $char = ''; |
|
| 603 | + $ischar = false; |
|
| 604 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 605 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 606 | + // 4 chars representing one unicode character |
|
| 607 | + $thisLetter = substr($source, $pos, 4); |
|
| 608 | + $pos += 4; |
|
| 609 | + } else { |
|
| 610 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 611 | + // 3 chars representing one unicode character |
|
| 612 | + $thisLetter = substr($source, $pos, 3); |
|
| 613 | + $pos += 3; |
|
| 614 | + } else { |
|
| 615 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 616 | + // 2 chars representing one unicode character |
|
| 617 | + $thisLetter = substr($source, $pos, 2); |
|
| 618 | + $pos += 2; |
|
| 619 | + } else { |
|
| 620 | + // 1 char (lower ascii) |
|
| 621 | + $thisLetter = substr($source, $pos, 1); |
|
| 622 | + $pos += 1; |
|
| 623 | + $char = $thisLetter; |
|
| 624 | + $ischar = true; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if ($ischar) { |
|
| 630 | + $encodedString .= $char; |
|
| 631 | + } else { // process the string representing the letter to a unicode entity |
|
| 632 | + $thisLen = strlen($thisLetter); |
|
| 633 | + $thisPos = 0; |
|
| 634 | + $decimalCode = 0; |
|
| 635 | + while ($thisPos < $thisLen) { |
|
| 636 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 637 | + if ($thisPos == 0) { |
|
| 638 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 639 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 640 | + } else { |
|
| 641 | + $charNum = intval($thisCharOrd - 128); |
|
| 642 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 643 | + } |
|
| 644 | + $thisPos++; |
|
| 645 | + } |
|
| 646 | + $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 647 | + $encodedString .= $encodedLetter; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $encodedString; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -667,32 +667,32 @@ discard block |
||
| 667 | 667 | **/ |
| 668 | 668 | function utf_32_to_unicode($source) { |
| 669 | 669 | |
| 670 | - // mb_string : methode rapide |
|
| 671 | - if (init_mb_string()) { |
|
| 672 | - $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF); |
|
| 673 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 674 | - |
|
| 675 | - return str_replace(chr(0), '', $source); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Sinon methode lente |
|
| 679 | - $texte = ''; |
|
| 680 | - while ($source) { |
|
| 681 | - $words = unpack("V*", substr($source, 0, 1024)); |
|
| 682 | - $source = substr($source, 1024); |
|
| 683 | - foreach ($words as $word) { |
|
| 684 | - if ($word < 128) { |
|
| 685 | - $texte .= chr($word); |
|
| 686 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 687 | - else { |
|
| 688 | - if ($word != 65279) { |
|
| 689 | - $texte .= '&#' . $word . ';'; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - return $texte; |
|
| 670 | + // mb_string : methode rapide |
|
| 671 | + if (init_mb_string()) { |
|
| 672 | + $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF); |
|
| 673 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 674 | + |
|
| 675 | + return str_replace(chr(0), '', $source); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Sinon methode lente |
|
| 679 | + $texte = ''; |
|
| 680 | + while ($source) { |
|
| 681 | + $words = unpack("V*", substr($source, 0, 1024)); |
|
| 682 | + $source = substr($source, 1024); |
|
| 683 | + foreach ($words as $word) { |
|
| 684 | + if ($word < 128) { |
|
| 685 | + $texte .= chr($word); |
|
| 686 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 687 | + else { |
|
| 688 | + if ($word != 65279) { |
|
| 689 | + $texte .= '&#' . $word . ';'; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + return $texte; |
|
| 696 | 696 | |
| 697 | 697 | } |
| 698 | 698 | |
@@ -710,21 +710,21 @@ discard block |
||
| 710 | 710 | * Caractère utf8 si trouvé, '' sinon |
| 711 | 711 | **/ |
| 712 | 712 | function caractere_utf_8($num) { |
| 713 | - $num = intval($num); |
|
| 714 | - if ($num < 128) { |
|
| 715 | - return chr($num); |
|
| 716 | - } |
|
| 717 | - if ($num < 2048) { |
|
| 718 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 719 | - } |
|
| 720 | - if ($num < 65536) { |
|
| 721 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 722 | - } |
|
| 723 | - if ($num < 1114112) { |
|
| 724 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - return ''; |
|
| 713 | + $num = intval($num); |
|
| 714 | + if ($num < 128) { |
|
| 715 | + return chr($num); |
|
| 716 | + } |
|
| 717 | + if ($num < 2048) { |
|
| 718 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 719 | + } |
|
| 720 | + if ($num < 65536) { |
|
| 721 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 722 | + } |
|
| 723 | + if ($num < 1114112) { |
|
| 724 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + return ''; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -737,30 +737,30 @@ discard block |
||
| 737 | 737 | **/ |
| 738 | 738 | function unicode_to_utf_8($texte) { |
| 739 | 739 | |
| 740 | - // 1. Entites € et suivantes |
|
| 741 | - $vu = array(); |
|
| 742 | - if (preg_match_all(',�*([1-9][0-9][0-9]+);,S', |
|
| 743 | - $texte, $regs, PREG_SET_ORDER)) { |
|
| 744 | - foreach ($regs as $reg) { |
|
| 745 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 746 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 751 | - |
|
| 752 | - // 2. Entites > ÿ |
|
| 753 | - //$vu = array(); |
|
| 754 | - if (preg_match_all(',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 755 | - $texte, $regs, PREG_SET_ORDER)) { |
|
| 756 | - foreach ($regs as $reg) { |
|
| 757 | - if (!isset($vu[$reg[0]])) { |
|
| 758 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 740 | + // 1. Entites € et suivantes |
|
| 741 | + $vu = array(); |
|
| 742 | + if (preg_match_all(',�*([1-9][0-9][0-9]+);,S', |
|
| 743 | + $texte, $regs, PREG_SET_ORDER)) { |
|
| 744 | + foreach ($regs as $reg) { |
|
| 745 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 746 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 751 | + |
|
| 752 | + // 2. Entites > ÿ |
|
| 753 | + //$vu = array(); |
|
| 754 | + if (preg_match_all(',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 755 | + $texte, $regs, PREG_SET_ORDER)) { |
|
| 756 | + foreach ($regs as $reg) { |
|
| 757 | + if (!isset($vu[$reg[0]])) { |
|
| 758 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 764 | 764 | |
| 765 | 765 | } |
| 766 | 766 | |
@@ -773,15 +773,15 @@ discard block |
||
| 773 | 773 | * Texte converti |
| 774 | 774 | **/ |
| 775 | 775 | function unicode_to_javascript($texte) { |
| 776 | - $vu = array(); |
|
| 777 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 778 | - $num = $regs[1]; |
|
| 779 | - $vu[$num] = true; |
|
| 780 | - $s = '\u' . sprintf("%04x", $num); |
|
| 781 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - return $texte; |
|
| 776 | + $vu = array(); |
|
| 777 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 778 | + $num = $regs[1]; |
|
| 779 | + $vu[$num] = true; |
|
| 780 | + $s = '\u' . sprintf("%04x", $num); |
|
| 781 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + return $texte; |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | /** |
@@ -793,11 +793,11 @@ discard block |
||
| 793 | 793 | * Texte converti |
| 794 | 794 | **/ |
| 795 | 795 | function javascript_to_unicode($texte) { |
| 796 | - while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) { |
|
| 797 | - $texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte); |
|
| 798 | - } |
|
| 796 | + while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) { |
|
| 797 | + $texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte); |
|
| 798 | + } |
|
| 799 | 799 | |
| 800 | - return $texte; |
|
| 800 | + return $texte; |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -809,11 +809,11 @@ discard block |
||
| 809 | 809 | * Texte converti |
| 810 | 810 | **/ |
| 811 | 811 | function javascript_to_binary($texte) { |
| 812 | - while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) { |
|
| 813 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 814 | - } |
|
| 812 | + while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) { |
|
| 813 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 814 | + } |
|
| 815 | 815 | |
| 816 | - return $texte; |
|
| 816 | + return $texte; |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | |
@@ -831,26 +831,26 @@ discard block |
||
| 831 | 831 | * @return string |
| 832 | 832 | */ |
| 833 | 833 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') { |
| 834 | - static $trans = []; |
|
| 835 | - if ($charset == 'AUTO') { |
|
| 836 | - $charset = $GLOBALS['meta']['charset']; |
|
| 837 | - } |
|
| 838 | - if (!strlen($texte)) { |
|
| 839 | - return $texte; |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - $table_translit = 'translit' . $complexe; |
|
| 843 | - |
|
| 844 | - // 2. Translitterer grace a la table predefinie |
|
| 845 | - if (!isset($trans[$complexe])) { |
|
| 846 | - $trans[$complexe] = []; |
|
| 847 | - load_charset($table_translit); |
|
| 848 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 849 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 834 | + static $trans = []; |
|
| 835 | + if ($charset == 'AUTO') { |
|
| 836 | + $charset = $GLOBALS['meta']['charset']; |
|
| 837 | + } |
|
| 838 | + if (!strlen($texte)) { |
|
| 839 | + return $texte; |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + $table_translit = 'translit' . $complexe; |
|
| 843 | + |
|
| 844 | + // 2. Translitterer grace a la table predefinie |
|
| 845 | + if (!isset($trans[$complexe])) { |
|
| 846 | + $trans[$complexe] = []; |
|
| 847 | + load_charset($table_translit); |
|
| 848 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 849 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
@@ -873,14 +873,14 @@ discard block |
||
| 873 | 873 | * @return string |
| 874 | 874 | */ |
| 875 | 875 | function translitteration($texte, $charset = 'AUTO', $complexe = '') { |
| 876 | - // 0. Supprimer les caracteres illegaux |
|
| 877 | - include_spip('inc/filtres'); |
|
| 878 | - $texte = corriger_caracteres($texte); |
|
| 876 | + // 0. Supprimer les caracteres illegaux |
|
| 877 | + include_spip('inc/filtres'); |
|
| 878 | + $texte = corriger_caracteres($texte); |
|
| 879 | 879 | |
| 880 | - // 1. Passer le charset et les é en utf-8 |
|
| 881 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true))); |
|
| 880 | + // 1. Passer le charset et les é en utf-8 |
|
| 881 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true))); |
|
| 882 | 882 | |
| 883 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 883 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | /** |
@@ -895,17 +895,17 @@ discard block |
||
| 895 | 895 | * @return string |
| 896 | 896 | */ |
| 897 | 897 | function translitteration_complexe($texte, $chiffres = false) { |
| 898 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 898 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 899 | 899 | |
| 900 | - if ($chiffres) { |
|
| 901 | - $texte = preg_replace_callback( |
|
| 902 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 903 | - function($m) { return translitteration_chiffree($m[0]); }, |
|
| 904 | - $texte |
|
| 905 | - ); |
|
| 906 | - } |
|
| 900 | + if ($chiffres) { |
|
| 901 | + $texte = preg_replace_callback( |
|
| 902 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 903 | + function($m) { return translitteration_chiffree($m[0]); }, |
|
| 904 | + $texte |
|
| 905 | + ); |
|
| 906 | + } |
|
| 907 | 907 | |
| 908 | - return $texte; |
|
| 908 | + return $texte; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | * @return string |
| 918 | 918 | */ |
| 919 | 919 | function translitteration_chiffree($car) { |
| 920 | - return strtr($car, "'`?~.^+(-", "123456789"); |
|
| 920 | + return strtr($car, "'`?~.^+(-", "123456789"); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | * true s'il a un BOM |
| 931 | 931 | **/ |
| 932 | 932 | function bom_utf8($texte) { |
| 933 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 933 | + return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -947,18 +947,18 @@ discard block |
||
| 947 | 947 | * true si c'est le cas |
| 948 | 948 | **/ |
| 949 | 949 | function is_utf8($string) { |
| 950 | - return !strlen( |
|
| 951 | - preg_replace( |
|
| 952 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 953 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 954 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 955 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 956 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 957 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 958 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 959 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 960 | - . ',sS', |
|
| 961 | - '', $string)); |
|
| 950 | + return !strlen( |
|
| 951 | + preg_replace( |
|
| 952 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 953 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 954 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 955 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 956 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 957 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 958 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 959 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 960 | + . ',sS', |
|
| 961 | + '', $string)); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -970,10 +970,10 @@ discard block |
||
| 970 | 970 | * true si c'est le cas |
| 971 | 971 | **/ |
| 972 | 972 | function is_ascii($string) { |
| 973 | - return !strlen( |
|
| 974 | - preg_replace( |
|
| 975 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 976 | - '', $string)); |
|
| 973 | + return !strlen( |
|
| 974 | + preg_replace( |
|
| 975 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 976 | + '', $string)); |
|
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | /** |
@@ -992,58 +992,58 @@ discard block |
||
| 992 | 992 | **/ |
| 993 | 993 | function transcoder_page($texte, $headers = '') { |
| 994 | 994 | |
| 995 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 996 | - if (is_ascii($texte)) { |
|
| 997 | - #spip_log('charset: ascii'); |
|
| 998 | - return $texte; |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1002 | - if (bom_utf8($texte)) { |
|
| 1003 | - $charset = 'utf-8'; |
|
| 1004 | - $texte = substr($texte, 3); |
|
| 1005 | - } // charset precise par le contenu (xml) |
|
| 1006 | - else { |
|
| 1007 | - if (preg_match( |
|
| 1008 | - ',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1009 | - $charset = trim(strtolower($regs[1])); |
|
| 1010 | - } // charset precise par le contenu (html) |
|
| 1011 | - else { |
|
| 1012 | - if (preg_match( |
|
| 1013 | - ',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS', |
|
| 1014 | - $texte, $regs) |
|
| 1015 | - # eviter #CHARSET des squelettes |
|
| 1016 | - and (($tmp = trim(strtolower($regs[2]))) != 'charset') |
|
| 1017 | - ) { |
|
| 1018 | - $charset = $tmp; |
|
| 1019 | - } // charset de la reponse http |
|
| 1020 | - else { |
|
| 1021 | - if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1022 | - $charset = trim(strtolower($regs[1])); |
|
| 1023 | - } else { |
|
| 1024 | - $charset = ''; |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - // normaliser les noms du shif-jis japonais |
|
| 1030 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1031 | - $charset = 'shift-jis'; |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - if ($charset) { |
|
| 1035 | - spip_log("charset: $charset"); |
|
| 1036 | - } else { |
|
| 1037 | - // valeur par defaut |
|
| 1038 | - if (is_utf8($texte)) { |
|
| 1039 | - $charset = 'utf-8'; |
|
| 1040 | - } else { |
|
| 1041 | - $charset = 'iso-8859-1'; |
|
| 1042 | - } |
|
| 1043 | - spip_log("charset probable: $charset"); |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - return importer_charset($texte, $charset); |
|
| 995 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 996 | + if (is_ascii($texte)) { |
|
| 997 | + #spip_log('charset: ascii'); |
|
| 998 | + return $texte; |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1002 | + if (bom_utf8($texte)) { |
|
| 1003 | + $charset = 'utf-8'; |
|
| 1004 | + $texte = substr($texte, 3); |
|
| 1005 | + } // charset precise par le contenu (xml) |
|
| 1006 | + else { |
|
| 1007 | + if (preg_match( |
|
| 1008 | + ',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1009 | + $charset = trim(strtolower($regs[1])); |
|
| 1010 | + } // charset precise par le contenu (html) |
|
| 1011 | + else { |
|
| 1012 | + if (preg_match( |
|
| 1013 | + ',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS', |
|
| 1014 | + $texte, $regs) |
|
| 1015 | + # eviter #CHARSET des squelettes |
|
| 1016 | + and (($tmp = trim(strtolower($regs[2]))) != 'charset') |
|
| 1017 | + ) { |
|
| 1018 | + $charset = $tmp; |
|
| 1019 | + } // charset de la reponse http |
|
| 1020 | + else { |
|
| 1021 | + if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1022 | + $charset = trim(strtolower($regs[1])); |
|
| 1023 | + } else { |
|
| 1024 | + $charset = ''; |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + // normaliser les noms du shif-jis japonais |
|
| 1030 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1031 | + $charset = 'shift-jis'; |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + if ($charset) { |
|
| 1035 | + spip_log("charset: $charset"); |
|
| 1036 | + } else { |
|
| 1037 | + // valeur par defaut |
|
| 1038 | + if (is_utf8($texte)) { |
|
| 1039 | + $charset = 'utf-8'; |
|
| 1040 | + } else { |
|
| 1041 | + $charset = 'iso-8859-1'; |
|
| 1042 | + } |
|
| 1043 | + spip_log("charset probable: $charset"); |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + return importer_charset($texte, $charset); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | |
@@ -1067,26 +1067,26 @@ discard block |
||
| 1067 | 1067 | * Le texte coupé |
| 1068 | 1068 | **/ |
| 1069 | 1069 | function spip_substr($c, $start = 0, $length = null) { |
| 1070 | - // Si ce n'est pas utf-8, utiliser substr |
|
| 1071 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1072 | - if ($length) { |
|
| 1073 | - return substr($c, $start, $length); |
|
| 1074 | - } else { |
|
| 1075 | - substr($c, $start); |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - // Si utf-8, voir si on dispose de mb_string |
|
| 1080 | - if (init_mb_string()) { |
|
| 1081 | - if ($length) { |
|
| 1082 | - return mb_substr($c, $start, $length); |
|
| 1083 | - } else { |
|
| 1084 | - return mb_substr($c, $start); |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - // Version manuelle (cf. ci-dessous) |
|
| 1089 | - return spip_substr_manuelle($c, $start, $length); |
|
| 1070 | + // Si ce n'est pas utf-8, utiliser substr |
|
| 1071 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1072 | + if ($length) { |
|
| 1073 | + return substr($c, $start, $length); |
|
| 1074 | + } else { |
|
| 1075 | + substr($c, $start); |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + // Si utf-8, voir si on dispose de mb_string |
|
| 1080 | + if (init_mb_string()) { |
|
| 1081 | + if ($length) { |
|
| 1082 | + return mb_substr($c, $start, $length); |
|
| 1083 | + } else { |
|
| 1084 | + return mb_substr($c, $start); |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + // Version manuelle (cf. ci-dessous) |
|
| 1089 | + return spip_substr_manuelle($c, $start, $length); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | |
@@ -1105,40 +1105,40 @@ discard block |
||
| 1105 | 1105 | **/ |
| 1106 | 1106 | function spip_substr_manuelle($c, $start, $length = null) { |
| 1107 | 1107 | |
| 1108 | - // Cas pathologique |
|
| 1109 | - if ($length === 0) { |
|
| 1110 | - return ''; |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - // S'il y a un demarrage, on se positionne |
|
| 1114 | - if ($start > 0) { |
|
| 1115 | - $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1116 | - } elseif ($start < 0) { |
|
| 1117 | - return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - if (!$length) { |
|
| 1121 | - return $c; |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - if ($length > 0) { |
|
| 1125 | - // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1126 | - // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1127 | - $n = 0; |
|
| 1128 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1129 | - ; |
|
| 1130 | - } |
|
| 1131 | - $c = substr($c, 0, $n * $length); |
|
| 1132 | - // puis, tant qu'on est trop long, on coupe... |
|
| 1133 | - while (($l = spip_strlen($c)) > $length) { |
|
| 1134 | - $c = substr($c, 0, $length - $l); |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - return $c; |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - // $length < 0 |
|
| 1141 | - return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1108 | + // Cas pathologique |
|
| 1109 | + if ($length === 0) { |
|
| 1110 | + return ''; |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + // S'il y a un demarrage, on se positionne |
|
| 1114 | + if ($start > 0) { |
|
| 1115 | + $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1116 | + } elseif ($start < 0) { |
|
| 1117 | + return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + if (!$length) { |
|
| 1121 | + return $c; |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + if ($length > 0) { |
|
| 1125 | + // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1126 | + // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1127 | + $n = 0; |
|
| 1128 | + while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1129 | + ; |
|
| 1130 | + } |
|
| 1131 | + $c = substr($c, 0, $n * $length); |
|
| 1132 | + // puis, tant qu'on est trop long, on coupe... |
|
| 1133 | + while (($l = spip_strlen($c)) > $length) { |
|
| 1134 | + $c = substr($c, 0, $length - $l); |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + return $c; |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + // $length < 0 |
|
| 1141 | + return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | /** |
@@ -1152,14 +1152,14 @@ discard block |
||
| 1152 | 1152 | * La chaîne avec une majuscule sur le premier mot |
| 1153 | 1153 | */ |
| 1154 | 1154 | function spip_ucfirst($c) { |
| 1155 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1156 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1157 | - return ucfirst($c); |
|
| 1158 | - } |
|
| 1155 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1156 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1157 | + return ucfirst($c); |
|
| 1158 | + } |
|
| 1159 | 1159 | |
| 1160 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1160 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1161 | 1161 | |
| 1162 | - return $lettre1 . spip_substr($c, 1); |
|
| 1162 | + return $lettre1 . spip_substr($c, 1); |
|
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | /** |
@@ -1173,12 +1173,12 @@ discard block |
||
| 1173 | 1173 | * La chaîne en minuscules |
| 1174 | 1174 | */ |
| 1175 | 1175 | function spip_strtolower($c) { |
| 1176 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1177 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1178 | - return strtolower($c); |
|
| 1179 | - } |
|
| 1176 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1177 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1178 | + return strtolower($c); |
|
| 1179 | + } |
|
| 1180 | 1180 | |
| 1181 | - return mb_strtolower($c); |
|
| 1181 | + return mb_strtolower($c); |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1192,23 +1192,23 @@ discard block |
||
| 1192 | 1192 | * Longueur de la chaîne |
| 1193 | 1193 | */ |
| 1194 | 1194 | function spip_strlen($c) { |
| 1195 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1196 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1197 | - |
|
| 1198 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1199 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1200 | - return strlen($c); |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - // Sinon, utiliser mb_strlen() si disponible |
|
| 1204 | - if (init_mb_string()) { |
|
| 1205 | - return mb_strlen($c); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - // Methode manuelle : on supprime les bytes 10......, |
|
| 1209 | - // on compte donc les ascii (0.......) et les demarrages |
|
| 1210 | - // de caracteres utf-8 (11......) |
|
| 1211 | - return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1195 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1196 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1197 | + |
|
| 1198 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1199 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1200 | + return strlen($c); |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + // Sinon, utiliser mb_strlen() si disponible |
|
| 1204 | + if (init_mb_string()) { |
|
| 1205 | + return mb_strlen($c); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + // Methode manuelle : on supprime les bytes 10......, |
|
| 1209 | + // on compte donc les ascii (0.......) et les demarrages |
|
| 1210 | + // de caracteres utf-8 (11......) |
|
| 1211 | + return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | // Initialisation |
@@ -1218,14 +1218,14 @@ discard block |
||
| 1218 | 1218 | // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
| 1219 | 1219 | // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
| 1220 | 1220 | if (!isset($GLOBALS['meta']['pcre_u']) |
| 1221 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1221 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1222 | 1222 | ) { |
| 1223 | - include_spip('inc/meta'); |
|
| 1224 | - ecrire_meta('pcre_u', |
|
| 1225 | - $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1226 | - and test_pcre_unicode()) |
|
| 1227 | - ? 'u' : '' |
|
| 1228 | - ); |
|
| 1223 | + include_spip('inc/meta'); |
|
| 1224 | + ecrire_meta('pcre_u', |
|
| 1225 | + $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1226 | + and test_pcre_unicode()) |
|
| 1227 | + ? 'u' : '' |
|
| 1228 | + ); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | |
@@ -1241,17 +1241,17 @@ discard block |
||
| 1241 | 1241 | * en unicode : 💩 |
| 1242 | 1242 | */ |
| 1243 | 1243 | function utf8_noplanes($x) { |
| 1244 | - $regexp_utf8_4bytes = '/( |
|
| 1244 | + $regexp_utf8_4bytes = '/( |
|
| 1245 | 1245 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1246 | 1246 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1247 | 1247 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1248 | 1248 | )/xS'; |
| 1249 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1250 | - foreach ($z[0] as $k) { |
|
| 1251 | - $ku = utf_8_to_unicode($k); |
|
| 1252 | - $x = str_replace($k, $ku, $x); |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - return $x; |
|
| 1249 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1250 | + foreach ($z[0] as $k) { |
|
| 1251 | + $ku = utf_8_to_unicode($k); |
|
| 1252 | + $x = str_replace($k, $ku, $x); |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + return $x; |
|
| 1257 | 1257 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 76 | + if (find_in_path($charset.'.php', 'charsets/', true)) { |
|
| 77 | 77 | return $charset; |
| 78 | 78 | } else { |
| 79 | 79 | spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | static $pcre_ok = 0; |
| 160 | 160 | |
| 161 | 161 | if (!$pcre_ok) { |
| 162 | - $s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " "; |
|
| 162 | + $s = " ".chr(195).chr(169)."t".chr(195).chr(169)." "; |
|
| 163 | 163 | if (preg_match(',\W...\W,u', $s)) { |
| 164 | 164 | $pcre_ok = 1; |
| 165 | 165 | } else { |
@@ -260,38 +260,38 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | if (!isset($trans[$charset][$charset_cible])) { |
| 262 | 262 | $trans[$charset][$charset_cible] = array( |
| 263 | - $p . chr(128) => "€", |
|
| 264 | - $p . chr(129) => ' ', # pas affecte |
|
| 265 | - $p . chr(130) => "‚", |
|
| 266 | - $p . chr(131) => "ƒ", |
|
| 267 | - $p . chr(132) => "„", |
|
| 268 | - $p . chr(133) => "…", |
|
| 269 | - $p . chr(134) => "†", |
|
| 270 | - $p . chr(135) => "‡", |
|
| 271 | - $p . chr(136) => "ˆ", |
|
| 272 | - $p . chr(137) => "‰", |
|
| 273 | - $p . chr(138) => "Š", |
|
| 274 | - $p . chr(139) => "‹", |
|
| 275 | - $p . chr(140) => "Œ", |
|
| 276 | - $p . chr(141) => ' ', # pas affecte |
|
| 277 | - $p . chr(142) => "Ž", |
|
| 278 | - $p . chr(143) => ' ', # pas affecte |
|
| 279 | - $p . chr(144) => ' ', # pas affecte |
|
| 280 | - $p . chr(145) => "‘", |
|
| 281 | - $p . chr(146) => "’", |
|
| 282 | - $p . chr(147) => "“", |
|
| 283 | - $p . chr(148) => "”", |
|
| 284 | - $p . chr(149) => "•", |
|
| 285 | - $p . chr(150) => "–", |
|
| 286 | - $p . chr(151) => "—", |
|
| 287 | - $p . chr(152) => "˜", |
|
| 288 | - $p . chr(153) => "™", |
|
| 289 | - $p . chr(154) => "š", |
|
| 290 | - $p . chr(155) => "›", |
|
| 291 | - $p . chr(156) => "œ", |
|
| 292 | - $p . chr(157) => ' ', # pas affecte |
|
| 293 | - $p . chr(158) => "ž", |
|
| 294 | - $p . chr(159) => "Ÿ", |
|
| 263 | + $p.chr(128) => "€", |
|
| 264 | + $p.chr(129) => ' ', # pas affecte |
|
| 265 | + $p.chr(130) => "‚", |
|
| 266 | + $p.chr(131) => "ƒ", |
|
| 267 | + $p.chr(132) => "„", |
|
| 268 | + $p.chr(133) => "…", |
|
| 269 | + $p.chr(134) => "†", |
|
| 270 | + $p.chr(135) => "‡", |
|
| 271 | + $p.chr(136) => "ˆ", |
|
| 272 | + $p.chr(137) => "‰", |
|
| 273 | + $p.chr(138) => "Š", |
|
| 274 | + $p.chr(139) => "‹", |
|
| 275 | + $p.chr(140) => "Œ", |
|
| 276 | + $p.chr(141) => ' ', # pas affecte |
|
| 277 | + $p.chr(142) => "Ž", |
|
| 278 | + $p.chr(143) => ' ', # pas affecte |
|
| 279 | + $p.chr(144) => ' ', # pas affecte |
|
| 280 | + $p.chr(145) => "‘", |
|
| 281 | + $p.chr(146) => "’", |
|
| 282 | + $p.chr(147) => "“", |
|
| 283 | + $p.chr(148) => "”", |
|
| 284 | + $p.chr(149) => "•", |
|
| 285 | + $p.chr(150) => "–", |
|
| 286 | + $p.chr(151) => "—", |
|
| 287 | + $p.chr(152) => "˜", |
|
| 288 | + $p.chr(153) => "™", |
|
| 289 | + $p.chr(154) => "š", |
|
| 290 | + $p.chr(155) => "›", |
|
| 291 | + $p.chr(156) => "œ", |
|
| 292 | + $p.chr(157) => ' ', # pas affecte |
|
| 293 | + $p.chr(158) => "ž", |
|
| 294 | + $p.chr(159) => "Ÿ", |
|
| 295 | 295 | ); |
| 296 | 296 | if ($charset_cible != 'unicode') { |
| 297 | 297 | foreach ($trans[$charset][$charset_cible] as $k => $c) { |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 422 | 422 | ) { |
| 423 | 423 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 424 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 424 | + $trans[$charset][chr($key)] = '&#'.$val.';'; |
|
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -488,11 +488,11 @@ discard block |
||
| 488 | 488 | $h = dechex($e); |
| 489 | 489 | if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
| 490 | 490 | $s = $CHARSET_REVERSE[$charset][$e]; |
| 491 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 492 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 491 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($s); |
|
| 492 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($s); |
|
| 493 | 493 | } else { |
| 494 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 495 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 494 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($e); |
|
| 495 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($e); |
|
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | } |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 537 | 537 | ) { |
| 538 | 538 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 539 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 539 | + $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';'); |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | } |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | } |
| 644 | 644 | $thisPos++; |
| 645 | 645 | } |
| 646 | - $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 646 | + $encodedLetter = "&#".preg_replace('/^0+/', '', $decimalCode).';'; |
|
| 647 | 647 | $encodedString .= $encodedLetter; |
| 648 | 648 | } |
| 649 | 649 | } |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
| 687 | 687 | else { |
| 688 | 688 | if ($word != 65279) { |
| 689 | - $texte .= '&#' . $word . ';'; |
|
| 689 | + $texte .= '&#'.$word.';'; |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | } |
@@ -715,13 +715,13 @@ discard block |
||
| 715 | 715 | return chr($num); |
| 716 | 716 | } |
| 717 | 717 | if ($num < 2048) { |
| 718 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 718 | + return chr(($num >> 6) + 192).chr(($num & 63) + 128); |
|
| 719 | 719 | } |
| 720 | 720 | if ($num < 65536) { |
| 721 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 721 | + return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 722 | 722 | } |
| 723 | 723 | if ($num < 1114112) { |
| 724 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 724 | + return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | return ''; |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
| 778 | 778 | $num = $regs[1]; |
| 779 | 779 | $vu[$num] = true; |
| 780 | - $s = '\u' . sprintf("%04x", $num); |
|
| 780 | + $s = '\u'.sprintf("%04x", $num); |
|
| 781 | 781 | $texte = str_replace($regs[0], $s, $texte); |
| 782 | 782 | } |
| 783 | 783 | |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | **/ |
| 795 | 795 | function javascript_to_unicode($texte) { |
| 796 | 796 | while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) { |
| 797 | - $texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte); |
|
| 797 | + $texte = str_replace($regs[0], "&#".hexdec($regs[1]).";", $texte); |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | return $texte; |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | return $texte; |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | - $table_translit = 'translit' . $complexe; |
|
| 842 | + $table_translit = 'translit'.$complexe; |
|
| 843 | 843 | |
| 844 | 844 | // 2. Translitterer grace a la table predefinie |
| 845 | 845 | if (!isset($trans[$complexe])) { |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | * true s'il a un BOM |
| 931 | 931 | **/ |
| 932 | 932 | function bom_utf8($texte) { |
| 933 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 933 | + return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF)); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
| 1126 | 1126 | // (un caractere utf-8 prenant au maximum n bytes) |
| 1127 | 1127 | $n = 0; |
| 1128 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1128 | + while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) { |
|
| 1129 | 1129 | ; |
| 1130 | 1130 | } |
| 1131 | 1131 | $c = substr($c, 0, $n * $length); |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | |
| 1160 | 1160 | $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
| 1161 | 1161 | |
| 1162 | - return $lettre1 . spip_substr($c, 1); |
|
| 1162 | + return $lettre1.spip_substr($c, 1); |
|
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | /** |