jquery Uncaught SyntaxError:意外的标记ILLEGAL

With $.post send data to external php

Have following code (modified variable names) text_of_the_ad:"<?php echo htmlspecialchars( substr($arr[0]["SomeText"],0,70), ENT_QUOTES, "UTF-8"); ?>",

text_of_the_ad in external php will get with $_POST['text_of_the_ad']

$arr[0]["SomeText"] is text from mysql column SomeText

In Chrome Console see text_of_the_ad:"CITROEN C4 EXCLUSIVE 2.0 HDI DIESEL 5 DOOR HATCH LOW MILEAGE FSH FULL ",

enter image description here

And see error Uncaught SyntaxError: Unexpected token ILLEGAL

Why the error? May be because word FULL is in the next line and after word FSH there is no ",?

JavaScript doesn't support multiline strings just like that. The easiest way to hack around this would probably be to just replace a literal with \ before echoing:

<?php echo str_replace("
","\
",htmlspecialchars( substr($arr[0]["SomeText"],0,70), ENT_QUOTES, "UTF-8")); ?>

You could try using the line continuation character, which is \. So that your source would look like:

text_of_the_ad:"CITROEN C4 EXCLUSIVE 2.0 HDI DIESEL 5 DOOR HATCH LOW MILEAGE FSH\
FULL "

Multi-line strings in JavaScript must be escaped, but doing it this way is not going to always produce your desired behaviour - i.e. sometimes browsers might insert newline characters, sometimes they might not.