Sublime Text 2 Php Snippet省略变量

时间:2012-08-08 14:05:16

标签: php code-snippets

我在sublime text 2中创建了以下代码段,但是当我在Php脚本中使用它时,它会自动删除所有变量(而不是它们的值)。

<snippet>
<content><![CDATA[

include 'constants.php';

// Defining connection

$connection = mysqli_connect(HOST, USERNAME, PASSWORD);

// If unable to connect

if(!$connection)
{
$error = 'Unable to connect to database server';
echo $error;
exit();
}

// Checking the encoding

if(!mysqli_set_charset($connection, 'utf8'))
{
$error =  'Unable to set database connection decoding';
echo $error;
exit();
}

// Selecting Database

if (!mysqli_select_db($connection, DATABASE))
{
$error = 'Unable to locate the .'. DATABASE;    
echo $error;    
exit();
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>phpMysqlConnection</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.php</scope> -->
</snippet>

真的发生了什么?

2 个答案:

答案 0 :(得分:21)

你需要用反斜杠“\”来转义每个“$”。

\$error;

答案 1 :(得分:3)

在变量前面添加\字符,因为sublime文本使用$ sign作为占位符。