Reputation: 8426
I'm passing a multiline string from PHP to Javascript and I am getting a Unexpected Token Illegal
error
I think the fact that its multi-line is causing the error but I'm not sure. I don't even need the string to be multi-line but it is stored as multiline in the database (and there's nothing I can do to change that).
This is what I tried to remove the multi-line characters but it didn't work
$str= str_replace(array("",json_decode('\u000A'),json_decode('\u000B'),
json_decode('\u000C'),json_decode('\u000D'),
json_decode('\u0085'),json_decode('\u2028'),
json_decode('\u2029')),"",$str);
Basically I attempted to remove all types of new line characters from the string
I've checked the other questions but they don't seem to solve the issue
I either need a fix on the PHP or the javascript side. Using Chrome
Thanks
Upvotes: 0
Views: 705
Reputation: 318488
Neither of those strings are valid JSON. They would be if you had quotes inside.. i.e. json_decode('"\u000A"')
Upvotes: 3