I have a string and it contains some words that I want to reach, seperators can be any string that consist of ,
;
or a space.
Here is a example:
;,osman,ali;, mehmet ;ahmet,ayse; ,
I need to take words osman
ali
mehmet
ahmet
and ayse
to an array or any type that I can use them one by one. I tried it by using preg function but i couldn't figure out.
If anyone help, I will be appreciative.
$words = preg_split('/[,;\s]+/', $str, -1, PREG_SPLIT_NO_EMPTY);
[,;\s]
is a character group which means match any of the characters contained in this group.\s
matches any white space character (space, tab, newline, etc.). If this is too much just replace it with a space: [,; ]
.+
means match one or more of the preceding symbol or group.http://www.regular-expressions.info/ is a good site to learn regular expressions.