You need to read these two questions (and answers):
So it's good to know that you can, in most situations, set a standard to avoid confusion between PHP and JS code. Thus avoiding the escape character (the \
).
This character is only needed when they get confused. For example. You are using double quotation marks in the PHP text. And inside it has double-quoted HTML code as well. These quotes there in HTML will close the PHP text and it is not what you want. Then use \"
or \'
, so the PHP interpreter will know that those quotes are part of the text and not the indicator that it is being closed.
It's annoying to do this. So it's better to choose one type for the code in one language and the other type in the other code.
I usually use single quotes in PHP and double in HTML. Except in rare cases this may prove to be worse.
When you have JS code inside HTML, you do not have much of a way, you have to go back to using the same type of quotation marks that HTML has already used or that PHP has already used and has to use the escape .
So it's best to leave JS code out of HTML as much as possible.
Note that in your sample code you are not using the escape backslash. In the description of the levels problem, you used it correctly.
PHP escape characters .
Escape Characters from JS .