I have a string :
$str = " Côte-d'azure ! (3000) limousin - limousine ";
And I need to extract some words and put them in an array. to get finally :
array (
0 => "Côte-d'azure",
1 => "limousin",
2 => "limousine"
);
So I tried :
preg_match_all("/[a-zA-Z]+/", $str, $all);
but this ignore the special character ô , ‘ and –
please any advise ?
Use Unicode mode
uand character properties:This requires one (Unicode) letter and then matches as many other Unicode letters, backslashes, hyphens and apostrophes as possible. If you want other punctuation characters to not separate a word, include it in the character class.
Note that 5 backslashes. Three backslashes are removed when the string is compiled, because two of them escape the backslash following them, and the last one escapes the
'. So the regex engine receives only 2 backslashes. These are interpreted by the regex engine as one literal backslash. Unfortunately there is no way to use less than 4 backslashes to represent one literal backslash when using PHP.