Hello,
I would like to extract individual words from a string. I want to ignore any punctuation marks.
At the moment, I am using the following:
$words = preg_replace("/[^a-zA-Z\s]/", "", $words);
$resultingWords = explode(" ", $words);
This works to a certain extent but if there are two spaces inbetween a word then the space is 'exploded' as a word if you get what I mean.
For example "This, for example, (note that was 2 spaces just now) would result in the following array!" - see attachment.
So punctuation has been stripped out as required and only characters left, but where there were 2 blanks one of them has been interpreted as part of the array.
Is there a way I can avoid this? If i strip out all blanks I end up with just one long string. Probably there is a better way of approaching this?
I'd appreciate any suggestions.
Thanks,
Tim.