B
B
busidoway2016-11-14 02:46:34
PHP
busidoway, 2016-11-14 02:46:34

How to split a string into characters using preg_split without spaces?

I'm trying to split the string into characters and put it into an array using preg_split, but spaces are added along with all the characters.
$text = 'plain text';
$text_trim = trim($text);
$str = preg_split('//u',$text_trim,-1,PREG_SPLIT_NO_EMPTY);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
roswell, 2016-11-14
@busidoway

$str = preg_split('/\s+|/u', $text_trim, -1, PREG_SPLIT_NO_EMPTY);

X
xmoonlight, 2016-11-14
@xmoonlight

$text_trim = preg_replace('/[\s]+/u','',$text);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question