Reputation: 73
I'm working on some PHP stuff but because I don't want to write the entire defafault PHP/HTML stuff so I was making a snippet in VSCode. But then when I needed to use a $_POST[]
in the snippet it wouldn't work because that it will use it as tabstop.
I've been trying to fix this I read somewhere that I needed to put a \
in front of the $
but that makes the $
not appear at all.
Here is my snippet:
"phpquickboilerplate": {
"prefix": "phpq",
"body": [
"\t\t\t$4: <input type=\"${5|button,checkbox,color,date,datetime-local,email,file,hidden,image,month,number,password,radio,range,reset,search,submit,tel,text,time,url,week|}\" name=\"${6:name1}\" value=\"<?php if (empty($_POST[\"${6:name1}\"])) {echo \"$7\";} else {echo $_POST[\"${6:name1}\"];} ?>\" />",
],
"description": "phpquickboilerplate"
}
How can I use the $
without making a tabstop?
Upvotes: 1
Views: 283
Reputation: 136936
You're right that \
can be used to escape $
, but the \
itself must also be escaped since it's in a JSON string, so you end up with
\\$_POST
Visual Studio Code should show an error when you just use \$_POST
. On my machine, I see \$
in red and the whole string gets underlined, but when I use \\$
the \\
goes yellow and the underlining goes away.
Upvotes: 2