I have a sentence like this
@abc sdf @def wer rty @ghi xyz
I want this in an array with key and value pairs like bellow and neglect the multiple spaces before @. My requirement is take whatever is there immediate next @(ex:abc in above sentence) as array key and whatever further before @ and key as explained take it as value(ex:sdf and wer rty in above sentence)
array(
[abc]=>sdf
[def]=>wer rty
[ghi]=>xyz
)
After lot of search and practice I got this much using preg_match_all()
array(
[0]=>abc
[1]=>def
[2]=>ghi
)
This is my existing code
$sentence = "@abc sdf @def wer rty @ghi xyz"
if (preg_match_all('/(?<!\w)@(\w+)/', $sentence, $matches)){
$splitted = $matches[1];
print_r($splitted);
exit;
}