I don't think that:
Code:
$output = str_replace($find,$replace.$find, $output);
is correct. You evaluate an expression there which maybe will cause endless loop by having $find there, which is also the first argument. I haven't seen all your code, but if you want to use that expression is better to add another variable before. eg:
Code:
$mynewreplace = $replace.$find;
$output = str_replace($find,$mynewreplace, $output);
Maria