Reputation: 725
I want to find the text between two characters
$var ='J111 king Jadv oops J123 php';
In above variable i get only the letter start from J.
i need following output,
Starting J values as
Array ( [0] =>J111 [1] => Jadv [2] => J123)
and balance values as,
Array ( [0] =>king [1] => oops [2] => php)
Upvotes: 0
Views: 326
Reputation: 6345
You can try with :
$var ='J111 king Jadv oops J123 php';
//get all the words in array
$words = preg_split('/\s+/', $var);
//match all the words starting with letter J
preg_match_all('(J[^\s]+)', $var, $matches);
//words with matching letter
$words_with_letter = $matches[0];
//words without matching letter
$words_without_letter = array_values(array_diff($words,$words_with_letter));
Hope this helps for you :)
Upvotes: 1
Reputation: 49919
Regex to get all the J values (live demo: http://regexr.com?306v4 )
/(J[^\s]+)/g
Currently working on the other one.
Upvotes: 1