00001 <?php
00002
00003
00004
00005 class StringMBString {
00006
00007
00008
00009
00010
00011
00012
00013 public function check_encoding($value, $encoding = false) {
00014 if (empty($encoding)) {
00015 $encoding = GyroLocale::get_charset();
00016 }
00017 return mb_check_encoding($value, $encoding);
00018 }
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 public function convert($value, $from = false, $to = false) {
00029 if (empty($to)) { $to = GyroLocale::get_charset(); }
00030
00031 $ret = $value;
00032 if (empty($from)) {
00033
00034 if (!$this->check_encoding($value, $to)) {
00035 $ret = mb_convert_encoding($value, $to);
00036 }
00037 }
00038 else {
00039 $ret = mb_convert_encoding($value, $to, $from);
00040 }
00041 return $ret;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 public function to_lower($val) {
00053 return mb_strtolower($val, GyroLocale::get_charset());
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063 public function to_upper($val) {
00064 return mb_strtoupper($val, GyroLocale::get_charset());
00065 }
00066
00067
00068
00069
00070 public function length($val) {
00071 return mb_strlen($val, GyroLocale::get_charset());
00072 }
00073
00074 public function strpos($haystack, $needle, $offset = NULL) {
00075 return mb_strpos($haystack, $needle, $offset, GyroLocale::get_charset());
00076 }
00077
00078 public function stripos($haystack, $needle, $offset = NULL) {
00079 return mb_stripos($haystack, $needle, $offset, GyroLocale::get_charset());
00080 }
00081
00082 public function strrpos($haystack, $needle) {
00083 if ($haystack == '') {
00084 return false;
00085 }
00086 return mb_strrpos($haystack, $needle, GyroLocale::get_charset());
00087 }
00088
00089
00090
00091
00092 public function substr($val, $start = 0, $length = NULL) {
00093 if ($length === NULL) {
00094 $length = $this->length($val);
00095 }
00096 return mb_substr($val, $start, $length, GyroLocale::get_charset());
00097 }
00098 }