-
- $str="Scripting School: http://bbs.it-home.org";
- function mbstringtoarray($str,$charset) {
- $strlen=mb_strlen($str) ;
- while($strlen){
- $array[]=mb_substr($str,0,1,$charset);
- $str=mb_substr($str,1,$strlen,$charset);
- $strlen=mb_strlen ($str);
- }
- return $array;
- }
- $arr=mbstringtoarray($str,"gb2312");
- ?>
Copy code
Note:
1. The $charset variable is the web page encoding, such as "gb2312" or "utf-8";
2. The first method requires that the server must enable the mbstring.dll extension, otherwise the code will execute incorrectly, so for those who use virtual hosts, you can consider using the second method.
Method 2:
-
- function str_to_arr($str){
- $l=strlen($str);
- for($i=0;$i<$l;$i++){
- $arr[ ]=ord($str[$i])>127?$str[$i].$str[++$i]:$str[$i];
- }
- return $arr;
- }
- $arr =str_to_arr($str);
- ?>
Copy code
|