Here's a reusable function to remove an arbitrarily delimited section of a string:
function str_remove_section($str, $start, $end, $repl = '')
{
if ((($pos_1 = strpos($str, $start)) === false) ||
($pos_1 > strlen($str) - (strlen($start) + strlen($end))) ||
(($pos_2 = strpos($str, $end, $pos_1 + 1)) === false)) {
return false;
}
$del_len = $pos_2 - $pos_1 + strlen($end);
$del = substr($str, $pos_1, $del_len);
$new = str_replace($del, $repl, $str);
return $new;
}
$string = 'hello/**comment
comment
**/goodbye';
$start_str = '/*';
$end_str = '*/';
$replace_str = ' ';
$new_string = str_remove_section($string, $start_str, $end_str, $replace_str);
if ($new_string) {
echo $new_string;
}