String to array

Jmnote (토론 | 기여)님의 2018년 8월 17일 (금) 22:02 판 (→‎PHP)
string to array
str_split()

1 JavaScript

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

2 Perl

use utf8;
@query=split '', 'ABC안녕123★';
print "$_, " for @query;
# A, B, C, 안, 녕, 1, 2, 3, ★,

3 PHP

<?php
function mb_str_split( $str ) { 
	return preg_split('/(?<!^)(?!$)/u', $str ); 
} 
$str = 'ABC안녕123★';
$chs = mb_str_split($str);
foreach($chs as $ch) echo "$ch, ";
# A, B, C, 안, 녕, 1, 2, 3, ★,

4 같이 보기

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