I have been wrapping my head around this for several days, but nothing gives the desired result.
Example:
$var = "Some Words - Other Words (More Words) Dash-Binded-Word";
Desired Result:
array(
[0] => Some Words
[1] => Other Words
[2] => More Words
[3] => Dash-Bound-Word
)
I managed to get all this using preg_match_all, but then Dash-Bound-Word broke. Trying to compare it with the surrounding spaces did not work, as this would break all the words except those attached to them.
The preg_match_all statement used (which also broke the words associated with the dash):
preg_match_all('#\(.*?\)|\[.*?\]|[^?!\-|\(|\[]+#', $var, $array);
Of course, I'm not a specialist on preg_match, preg_split, so any help here would be very appreciated.
source
share