Seriously, what am I missing here? You just want to get the words out the sentence right?
$sentence = "How are you doing today? I am doing fine, why thank you.";
preg_match_all('/[a-z]+/i', $sentence, $string);
var_dump($string);
/* RETURNS THIS:
array(1) { [0]=> array(12) { [0]=> string(3) "How" [1]=> string(3) "are" [2]=> string(3) "you" [3]=> string(5) "doing" [4]=> string(5) "today" [5]=> string(1) "I" [6]=> string(2) "am" [7]=> string(5) "doing" [8]=> string(4) "fine" [9]=> string(3) "why" [10]=> string(5) "thank" [11]=> string(3) "you" } }
*/
If you just want to break the words up based on spaces(this includes tabs and line breaks, check this:
$sentence = "How are you doing today? I am doing fine, why thank you.";
preg_match_all('/[^[:space:]]+/i', $sentence, $string);
var_dump($string);
/* RETURNS THIS (with punctuations):
array(1) { [0]=> array(12) { [0]=> string(3) "How" [1]=> string(3) "are" [2]=> string(3) "you" [3]=> string(5) "doing" [4]=> string(6) "today?" [5]=> string(1) "I" [6]=> string(2) "am" [7]=> string(5) "doing" [8]=> string(5) "fine," [9]=> string(3) "why" [10]=> string(5) "thank" [11]=> string(4) "you." } }
*/
I admit, I may be missing something, but does this work for you???