1

I'm trying to split a string into an array. I've tried str_split() but the problem is that characters like "äüöÄÜÖß" don't work (they become questionmarks)

So I'm trying to do the same with mb_split(), but I don't know how to get the right Regex for it.

Can you please help me?

Here is the code:

$arr = mb_split("\.", $str);

2 Answers 2

4

You might try:

$arr = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);

For the /u modifier, see http://php.net/manual/en/reference.pcre.pattern.modifiers.php :

"u (PCRE8) This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5."

Sign up to request clarification or add additional context in comments.

2 Comments

I want to get an array like ["w", "o", "r", "d"] out of "word"
You're right, but I did get you started in the right direction! I've updated my answer, per your suggestion.
3

ok. that's it:

$arr = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.