Advertisement
sagaida

Untitled

May 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1.     public function utf8_str_split($str) {
  2.         // place each character of the string into and array
  3.         $split=1;
  4.         $array = array();
  5.         for ( $i=0; $i < strlen( $str ); ){
  6.           $value = ord($str[$i]);
  7.           if($value > 127){
  8.             if($value >= 192 && $value <= 223)
  9.               $split=2;
  10.             elseif($value >= 224 && $value <= 239)
  11.               $split=3;
  12.             elseif($value >= 240 && $value <= 247)
  13.               $split=4;
  14.           }else{
  15.             $split=1;
  16.           }
  17.             $key = NULL;
  18.           for ( $j = 0; $j < $split; $j++, $i++ ) {
  19.             $key .= $str[$i];
  20.           }
  21.           array_push( $array, $key );
  22.         }
  23.         return $array;
  24.       }
  25.    
  26.     public function clearstr($str){
  27.         $sru = 'ёйцукенгшщзхъфывапролджэячсмитьбю';
  28.         $s1 = array_merge($this->utf8_str_split($sru), $this->utf8_str_split(strtoupper($sru)), range('A', 'Z'), range('a','z'), range('0', '9'), array('&','«','»',' ','#',';','%','?',':','(',')','-','_','=','+','[',']',',','.','/','\\'));
  29.         $codes = array();
  30.         for ($i=0; $i<count($s1); $i++){
  31.                 $codes[] = ord($s1[$i]);
  32.         }
  33.         $str_s = $this->utf8_str_split($str);
  34.         for ($i=0; $i<count($str_s); $i++){
  35.                 if (!in_array(ord($str_s[$i]), $codes)){
  36.                         $str = str_replace($str_s[$i], '', $str);
  37.                 }
  38.         }
  39.         return $str;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement