Here is my code:
$str = "this is a test"
$arr = explode(' ', $str);
/* output:
array (
0 => "this",
1 => "is",
2 => a,
3 => test
)
All I'm trying to do is adding this condition to the explode()
function:
if the word of
a
is followed by the word oftest
, then consider them as one word.
So this is expected output:
/* expected output:
array (
0 => "this",
1 => "is",
2 => a test
)
In other word, I want something like this: /a[ ]+test|[^ ]+/
. But I cannot use mentioned pattern as an alternative for explode()
function. Because in reality, there is lots of bipartite-words which I need to care about. I mean there is an array of words which I want to be considered as one word:
$one_words("a test", "take off", "go away", "depend on", ....);
Any idea?