3 * @version $Id: trim.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
8 //---------------------------------------------------------------
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
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 //---------------------------------------------------------------
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
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 //---------------------------------------------------------------
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
65 function utf8_trim( $str, $charlist = FALSE ) {
66 if($charlist === FALSE) return trim($str);
67 return utf8_ltrim(utf8_rtrim($str, $charlist), $charlist);