php: Split sentence into words (with special word list)
I have sentence:
$text = "word word, dr. word: a.sh. word a.k word?!..";
special words are: "dr." , "a.sh" and "a.k"
this :
$text = "word word, dr. word: a.sh. word a.k word?!..";
$split = preg_split("/[^\w]([\s]+[^\w]|$)/", $text, -1, PREG_SPLIT_NO_EMPTY);
print_r($split);
regular expression gives me this:
Array (
[0] => word
[1] => word
[2] => dr
[3] => word
[4] => a.sh
[5] => word
[6] => a.k
[7] => word )
and i need
Array (
[0] => word
[1] => word
[2] => dr. #<----- point must be here becouse "dr." is special word [3] =>
word
[4] => a.sh. #<----- point must be here becouse "a.sh" is special word [5]
=> word
[6] => a.k
[7] => word)
No comments:
Post a Comment