Parse a string into separate words
Parse a string into separate words (array output).
function parser($str, $char = ' ') { $str = trim($str); $str = $str . $char; $len = strlen($str); $words = array(); $w = ''; $c = 0; for ($i = 0; $i < $len; $i++) if ($str[$i] != $char) $w = $w . $str[$i]; else if (($w != $char) and ($w != '')) { $words[$c] = $w; $c++; $w = ''; } return $words; } $x = parser('hello world!'); print_r($x);