note 83331 modified in function.str-split by danbrown

From: Date: Mon, 04 Aug 2008 15:23:49 +0000
Subject: note 83331 modified in function.str-split by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143136@lists.php.net to get a copy of this message
This function supportes utf8 (improvement of function str_split_php4) i tried this function successfully with these languages 1- Chinese 2- Japanese 3- Arabic 4- Turkish 5- Urdu 6- Russian 7- Persian <?php function str_split_php4_utf8($str) { // place each character of the string into and array $split=1; $array = array(); for ( $i=0; $i < strlen( $str ); ){ $value = ord($str[$i]); if($value > 127){ if($value >= 192 && $value <= 223) $split=2; elseif($value >= 224 && $value <= 239) $split=3; elseif($value >= 240 && $value <= 247) $split=4; }else{ $split=1; } $key = NULL; for ( $j = 0; $j < $split; $j++, $i++ ) { $key .= $str[$i]; } array_push( $array, $key ); } return $array; } ?> --was-- This function supportes utf8 (improvement of function str_split_php4) i tried this function successfully with these languages 1- Chinese 2- Japanese 3- Arabic 4- Turkish 5- Urdu 6- Russian 7- Persian <?php function str_split_php4_utf8($str) { // place each character of the string into and array $split=1; $array = array(); for ( $i=0; $i < strlen( $str ); ){ $value = ord($str[$i]); if($value > 127){ if($value >= 192 && $value <= 223) $split=2; elseif($value >= 224 && $value <= 239) $split=3; elseif($value >= 240 && $value <= 247) $split=4; }else{ $split=1; } $key = NULL; for ( $j = 0; $j < $split; $j++, $i++ ) { $key .= $str[$i]; } array_push( $array, $key ); } return $array; } ?> http://php.net/manual/en/function.str-split.php

« previous php.notes (#143136) next »