How can I write Snippets in Visual Studio Code with an “$” inside of them?

43
April 13, 2019, at 11:00 PM

I want to make a Code-Snippet in VSC but when I make a snippet and paste the code with "$" inside of it the "$" dissapears. I know why but I dont know how I can fix this.

This is for a PHP Site I'm coding on.

//MYSQL - VERBINDUNG
"MySQL Verbindung": {
    "prefix": "db_verbinden",
    "body": [
        "$dburl = 'localhost';",
        "$username = 'root';",
        "$passwort = '';",
        "$dbselect = 'db';",
        "",
        "$db = mysqli_connect($dburl, $username, $passwort) or die('Die Verbindung mit der Datenbank ist fehlgeschlagen!');",
        "mysqli_select_db('rbcms', $db);",
        "",
    ]
},

So I want to make Snippets with "$" inside of them.

Answer 1

As it is mentioned in the documentation you need to escape certain characters:

Below is the EBNF (extended Backus-Naur form) for snippets. With \(backslash), you can escape $, } and \. Within choice elements, the backslash also escapes comma and pipe characters.

https://code.visualstudio.com/docs/editor/userdefinedsnippets#_grammar

READ ALSO
Memory exhausted (minimal script)

Memory exhausted (minimal script)

This is something that has never happened to me before

67
Session in other page don't display the value

Session in other page don't display the value

I have a page with checkbox, every checkbox can be set on true, if on true, the products id is added accross an ajax inside an array

38
How to solve PHP Error installing Composer on CentOS7

How to solve PHP Error installing Composer on CentOS7

When I run sudo yum install composer on CentOS7 I get this error

279