How to pass a PHP variable to JavaScript without errors and escaping
Hello everyone! I'm a beginner in PHP and JavaScript, and I've encountered a problem that seems like it should be simple, but I can't find the right solution.
I have a PHP script that retrieves data from a database (for example, a username or message text). I need to pass this variable to JavaScript to use it, say, for displaying in a modal window or for sending via AJAX.
The problem is that when I simply insert a PHP variable into JavaScript code, everything breaks if the string contains quotes, apostrophes, or, even worse, newline characters (\n). For example:
```php
```
In this case, J