String to array

Jmnote (토론 | 기여)님의 2016년 4월 22일 (금) 10:40 판 (→‎PHP)
string to array
str_split()

1 JavaScript

var chars = 'ABC안녕123★'.split('');
console.log( chars );
// ["A", "B", "C", "안", "녕", "1", "2", "3", "★"]

2 PHP

function mb_str_split( $str ) { 
	return preg_split('/(?<!^)(?!$)/u', $str ); 
} 

$str = 'ABC안녕123★';
$arr = mb_str_split($str);
print_r($arr);
# Array
# (
#     [0] => A
#     [1] => B
#     [2] => C
#     [3] => 안
#     [4] => 녕
#     [5] => 1
#     [6] => 2
#     [7] => 3
#     [8] => ★
# )

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}