@php function js_safe($str) { $str = (string)$str; $str = str_replace(["\r", "\n"], ' ', $str); $str = str_replace("'", "\\'", $str); $str = str_replace('"', '\\"', $str); $str = preg_replace('/\s+/', ' ', $str); return trim($str); } @endphp