5

It seems when using PHP variables like $_SERVER the code snippet ignores the $. For example

{
// Example:
"IP Address Test": {
    "scope": "php",
    "prefix": "iptest",
    "body": [
                "// Debugging",
                "if($_SERVER[\"REMOTE_ADDR\"]=='${1:ipaddress}'){",
                "\t//run only my ip",
                "\t$0",
                "}"
    ],
    "description": "Test only from IP address"
}

}

outputs :

// Debugging
if(_SERVER["REMOTE_ADDR"]=='xxx.xxx.xxx.xxx'){
//run only my ip

}
1
  • 2
    Double back-slashes \\$ is probably the right way to do it. Commented Jul 19, 2019 at 1:25

2 Answers 2

8

You can't use \ you have to use double $ ..

eg.

// Debugging
if($$_SERVER["REMOTE_ADDR"]=='xxx.xxx.xxx.xxx'){
    //run only my ip

}
Sign up to request clarification or add additional context in comments.

Comments

0

I can't add a comment, but Mark has the correct answer.

$$ places the cursor at the beginning of the $ once VSCode has rendered the string. \ correctly places the cursor where you want it instead of one at every $. So, instead of...

<--cursor-here-->$_SERVER

// before $ gives us

$_SERVER<--cursor-here-->

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.