Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00036 function isUTF8 ($aStr) {
00037 $field = "/^(";
00038 $field .="[\x09|\x0A|\x0D]|[\x20-\x7E]|";
00039 $field .="[\xC2-\xDF][\x80-\xBF]|";
00040 $field .="\xE0[\xA0-\xBF][\x80-\xBF]|";
00041 $field .="[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|";
00042 $field .="\xED[\x80-\x9F][\x80-\xBF]|";
00043 $field .="\xF0[\x90-\xBF][\x80-\xBF]{2}|";
00044 $field .="[\xF1-\xF3][\x80-\xBF]{3}|";
00045 $field .="\xF4[\x80-\x8F][\x80-\xBF]{2}";
00046 $field .=")*$/s";
00047 return preg_match($field, $AStr);
00048 }
00049
00050 function seems_not_utf8($AStr)
00051 {
00052
00053 $ptrASCII = '[\x00-\x7F]';
00054 $ptr2Octet = '[\xC2-\xDF][\x80-\xBF]';
00055 $ptr3Octet = '[\xE0-\xEF][\x80-\xBF]{2}';
00056 $ptr4Octet = '[\xF0-\xF4][\x80-\xBF]{3}';
00057 $ptr5Octet = '[\xF8-\xFB][\x80-\xBF]{4}';
00058 $ptr6Octet = '[\xFC-\xFD][\x80-\xBF]{5}';
00059
00060 if (preg_match("/^($ptrASCII|$ptr2Octet|$ptr3Octet|$ptr4Octet|$ptr5Octet|$ptr6Octet)*$/s", $AStr))
00061 {
00062 return true;
00063 }
00064 else
00065 {
00066 return false;
00067 }
00068 }
00069
00070 function getUTF8String($aStr) {
00071 if (!isUTF8($aStr)) {
00072
00073 return utf8_encode($aStr);
00074
00075 }
00076 return $aStr;
00077 }
00078
00079 ?>