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 character of escape (to \
).
This character is only needed when they get confused. For example. You are using double quotes in PHP text. And inside there’s HTML code with double quotes as well. These quotes there in HTML will close the PHP text and it’s not what you want. So use \"
or \'
, so the PHP interpreter will know that those quotes are part of the text and it is not the indicator that it is being terminated.
It’s boring to do this, so it’s best to choose one type for the code of one language and the other type in the other code.
I usually use single quotes in PHP and double quotes in HTML, except in the rare specific cases this can be worse.
When there is JS code inside the HTML, there is not much way, you have to go back to using the same kind of quotes that HTML already used or that PHP already used and have to use the character of escape.
This is why it is better to leave JS code out of HTML as much as possible.
Note that in your example code you are not using the backslash which is the escape. In the description of the levels problem, you used correctly.
Escape characters from PHP.
Escape characters from JS.
echo is not a function, so parenthesis is optional.
– rray