简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM