Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Multibyte safe version of trim()
- * Always strips whitespace characters (those equal to \s)
- *
- * @author Peter Johnson
- * @email [email protected]
- * @param $string The string to trim
- * @param $chars Optional list of chars to remove from the string ( as per trim() )
- * @param $chars_array Optional array of preg_quote'd chars to be removed
- * @return string
- */
- public static function mb_trim( $string, $chars = "", $chars_array = array() )
- {
- for( $x=0; $x<iconv_strlen( $chars ); $x++ ) $chars_array[] = preg_quote( iconv_substr( $chars, $x, 1 ) );
- $encoded_char_list = implode( "|", array_merge( array( "\s","\t","\n","\r", "\0", "\x0B" ), $chars_array ) );
- $string = mb_ereg_replace( "^($encoded_char_list)*", "", $string );
- $string = mb_ereg_replace( "($encoded_char_list)*$", "", $string );
- return $string;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement