* @return string
*/
public static function encodeJS($string) {
- // unify newlines
$string = self::unifyNewlines($string);
- $string = str_replace(["\\", "'", "\n", "/"], ["\\\\", "\'", '\n', '\/'], $string);
-
- // escape backslash
- $string = str_replace("\\", "\\\\", $string);
-
- // escape singe quote
- $string = str_replace("'", "\'", $string);
-
- // escape double quote
- $string = str_replace('"', '\"', $string);
-
- // escape new lines
- $string = str_replace("\n", '\n', $string);
-
- // escape slashes
- $string = str_replace("/", '\/', $string);
++ $string = str_replace(["\\", "'", '"', "\n", "/"], ["\\\\", "\'", '\"', '\n', '\/'], $string);
return $string;
}