source: trunk/web/punbb/include/utf8/utf8.php @ 10

Last change on this file since 10 was 6, checked in by dj3c1t, 13 years ago

mise a jour du trunk

File size: 2.3 KB
Line 
1<?php
2
3/**
4* This is the dynamic loader for the library. It checks whether you have
5* the mbstring extension available and includes relevant files
6* on that basis, falling back to the native (as in written in PHP) version
7* if mbstring is unavailabe.
8*
9* It's probably easiest to use this, if you don't want to understand
10* the dependencies involved, in conjunction with PHP versions etc. At
11* the same time, you might get better performance by managing loading
12* yourself. The smartest way to do this, bearing in mind performance,
13* is probably to "load on demand" - i.e. just before you use these
14* functions in your code, load the version you need.
15*
16* It makes sure the the following functions are available;
17* utf8_strlen, utf8_strpos, utf8_strrpos, utf8_substr,
18* utf8_strtolower, utf8_strtoupper
19* Other functions in the ./native directory depend on these
20* six functions being available
21* @package utf8
22*/
23
24// Check whether PCRE has been compiled with UTF-8 support
25$UTF8_ar = array();
26if (preg_match('/^.{1}$/u', "ñ", $UTF8_ar) != 1)
27        trigger_error('PCRE is not compiled with UTF-8 support', E_USER_ERROR);
28
29unset($UTF8_ar);
30
31// Put the current directory in this constant
32if (!defined('UTF8'))
33        define('UTF8', dirname(__FILE__));
34
35if (extension_loaded('mbstring') && !defined('UTF8_USE_MBSTRING') && !defined('UTF8_USE_NATIVE'))
36        define('UTF8_USE_MBSTRING', true);
37else
38        define('UTF8_USE_NATIVE', true);
39
40// utf8_strpos() and utf8_strrpos() need utf8_bad_strip() to strip invalid
41// characters. Mbstring doesn't do this while the Native implementation does.
42require UTF8.'/utils/bad.php';
43
44if (defined('UTF8_USE_MBSTRING'))
45{
46        /**
47        * If string overloading is active, it will break many of the
48        * native implementations. mbstring.func_overload must be set
49        * to 0, 1 or 4 in php.ini (string overloading disabled).
50        * Also need to check we have the correct internal mbstring
51        * encoding
52        */
53        if (ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING)
54                trigger_error('String functions are overloaded by mbstring', E_USER_ERROR);
55
56        mb_language('uni');
57        mb_internal_encoding('UTF-8');
58
59        if (!defined('UTF8_CORE'))
60                require UTF8.'/mbstring/core.php';
61}
62elseif (defined('UTF8_USE_NATIVE'))
63{
64        if (!defined('UTF8_CORE'))
65        {
66                require UTF8.'/utils/unicode.php';
67                require UTF8.'/native/core.php';
68        }
69}
70
71// Load the native implementation of utf8_trim
72require UTF8.'/trim.php';
Note: See TracBrowser for help on using the repository browser.