There must be a fast and efficient way to split a (text) string at the "nth" occurrence of a needle, but I cannot find it. There is a fairly full set of functions
function split_nth($haystack, $needle, $nth){ $result = array(); if(substr_count($haystack,$needle) > ($nth-1)){ $haystack = explode($needle, $haystack); $result[] = implode(array_splice($haystack, 0, $nth), $needle); $result[] = implode($haystack, $needle); } return $result; }