S
S
SHentai2018-05-06 00:04:43
PHP
SHentai, 2018-05-06 00:04:43

How to do 1,2,3,4 -> array(1,2,3,4)...?

Hello.
Need to do this:

1,2,3,4 -> array(1,2,3,4)
1 2 3 4 -> array(1,2,3,4)
1\n2\n3\n4 -> array(1,2,3,4)
1,2 3,4 -> array(1,2,3,4)
1\n2,3 4 -> array(1,2,3,4)

I think I showed it clearly, that is, I need a string with numbers that can be separated by (comma) (space) (hyphen), and whatever their combination, in place, out of place, you need to create an array with them.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-05-06
@SHentai

preg_split('/[^\d]+/', $str)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question