I am sending a sting as a parameter to a JavaScript function:
theJSFunction('say hi dude');
Chrome gives me SyntaxError: Unexpected token ILLEGAL so after research, I’ve found that the following whitespaces generates the error \u2028 and \u2029.
The problem is, the string posted to the function is printed via PHP and I need it to be printed via PHP (could use ajax, but I am required to let the PHP print it).
Is there any way to remove those to characters through PHP or JavaScript?
You can replace with
.replace. Passing a regular expressions with thegflag replaces all occurences, and you can include\uxxxxcharacters as well: