Sublime Text 2 Php代码片段省略变量

3

我在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>

到底发生了什么?


删除所有的 '$connection' 和 '$error' 变量。 - Yousuf Memon
2个回答

21

您需要用反斜杠“\”转义每个“$”符号。

\$error;

3
在变量前加上\字符,因为Sublime Text使用$符号作为占位符。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接