I need a regular expression that divides a string, more specifically a complete name of a person, and turns it into an array of words.
$string = "Wallace de Souza Vizerra";
$array = preg_split('/\s+/', $string, -1, PREG_SPLIT_NO_EMPTY);
['Wallace', 'de', 'Souza', 'Vizerra']
However, I need the result to be as follows when there are occurrences de
, da
, do
, das
and dos
.
['Wallace', 'de Souza', 'Vizerra']
Can someone with regular expression handle help me and explain to me how the regular expression used in the response would work?
If there is any way, I would also like to remove the first word through the regular expression as well.
That is
$string = "Wallace de Souza Vizerra"
should return
['de Souza', 'Vizerra']