I have a string like this:
$str="hello world 2 in 365 php";
I want this:
['hello world' , 'in' , 'php']
Any ideas?
I have a string like this:
$str="hello world 2 in 365 php";
I want this:
['hello world' , 'in' , 'php']
Any ideas?
I was bored:
$result = preg_split('/ ?\d+ ?/', $str);
Split on an optional space ?
followed by 1 or more digits \d+
followed by an optional space ?
. Just remove the ?
s if you want the spaces to be required.
That would do the work for you (I've split into multiple variables just to make sure you understand the way I've done that)
$str = "hello world 2 in 365 php";
$withoutNum = preg_replace('/[0-9]+/', '', $str);
$removedDoubleWhiteSpaces = preg_replace('/\s+/', ' ', $withoutNum);
$splitedArr = explode(' ', $removedDoubleWhiteSpaces);
var_dump($splitedArr);
Edit:
After I've read again, the solution which offered above of my solution is the ideal one. Sorry.