I have written a php function that should split a string up, remove the whitespaces and put all single words in an array. I always get an error that the allowed memory size is exhausted and the document.write() command only outputs the last word. It says that the strrpos() command is exhausting the memory. How can I fix this code to work properly?
divide_search();
function divide_search() {
global $search_string_php, $remaining_str;
$pos_p = strrpos((string) $search_string_php, " ");
if($pos_p == false) {
$str_parts[] = $remaining_str;
sort_search();
} else {
$p_part = substr($remaining_str, ($pos_p + 1),
strlen($remaining_str));
echo $p_part;
if(strlen($p_part) != 0) {
$str_parts[] = $p_part;
}
$remaining_str = substr($remaining_str, 0, $pos_p);
divide_search();
}
}