Fixing file upload params ($_FILES) normalization. Closes #75
[akelos.git] / vendor / phputf8 / trim.php
blob7f1cb3ee4027b5641e61558a1957f94f99ce5902
1 <?php
2 /**
3 * @version $Id: trim.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
4 * @package utf8
5 * @subpackage strings
6 */
8 //---------------------------------------------------------------
9 /**
10 * UTF-8 aware replacement for ltrim()
11 * Note: you only need to use this if you are supplying the charlist
12 * optional arg and it contains UTF-8 characters. Otherwise ltrim will
13 * work normally on a UTF-8 string
14 * @author Andreas Gohr <andi@splitbrain.org>
15 * @see http://www.php.net/ltrim
16 * @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php
17 * @return string
18 * @package utf8
19 * @subpackage strings
21 function utf8_ltrim( $str, $charlist = FALSE ) {
22 if($charlist === FALSE) return ltrim($str);
24 //quote charlist for use in a characterclass
25 $charlist = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$charlist);
27 return preg_replace('/^['.$charlist.']+/u','',$str);
30 //---------------------------------------------------------------
31 /**
32 * UTF-8 aware replacement for rtrim()
33 * Note: you only need to use this if you are supplying the charlist
34 * optional arg and it contains UTF-8 characters. Otherwise rtrim will
35 * work normally on a UTF-8 string
36 * @author Andreas Gohr <andi@splitbrain.org>
37 * @see http://www.php.net/rtrim
38 * @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php
39 * @return string
40 * @package utf8
41 * @subpackage strings
43 function utf8_rtrim( $str, $charlist = FALSE ) {
44 if($charlist === FALSE) return rtrim($str);
46 //quote charlist for use in a characterclass
47 $charlist = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$charlist);
49 return preg_replace('/['.$charlist.']+$/u','',$str);
52 //---------------------------------------------------------------
53 /**
54 * UTF-8 aware replacement for trim()
55 * Note: you only need to use this if you are supplying the charlist
56 * optional arg and it contains UTF-8 characters. Otherwise trim will
57 * work normally on a UTF-8 string
58 * @author Andreas Gohr <andi@splitbrain.org>
59 * @see http://www.php.net/trim
60 * @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php
61 * @return string
62 * @package utf8
63 * @subpackage strings
65 function utf8_trim( $str, $charlist = FALSE ) {
66 if($charlist === FALSE) return trim($str);
67 return utf8_ltrim(utf8_rtrim($str, $charlist), $charlist);