Sublime snippet for PHP print_r exit Array

Nowadays, The sublime is the developer and designer-friendly code editor. The sublime provide many plugins that make developing is too easy.

The sublime provide a functionality for write our own snippet as we want. Let’s see how we can create the snippet o sublime. We write snippet for print_r and exit like.

echo '<pre>';
print_r($variable);
exit;

The PHP developer has written those line many times on the day. So we will create a snippet for that first of all let’s open sublime.

Let’s open snippet file.

Tools > Developer > New Snippet...

The new file is created with the below content.

<snippet>
    <content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

Now, We will customize this snippet as we want. So let’s change below snippet for print_r and exit pre define syntax.

<snippet>
    <content><![CDATA[echo '<pre>';
print_r(${1:this});
exit;]]></content>
    <!-- Optional: Tab trigger to activate the snippet -->
    <tabTrigger>pr</tabTrigger>
    <!-- Optional: Scope the tab trigger will be active in -->
    <scope>source.php</scope>
    <!-- Optional: Description to show in the menu -->
    <description>The Coding Stuff Snippet</description>
</snippet>

Out snippet is ready now let’s save it with “thecodingstuff.sublime-snippet” file make sure the file extension is “sublime-snippet”.

Let’s explain the snippet, First, we wrote the coding syntax “<content></content>” section.

Then wrote the snippet word “<tabTrigger></tagTrigger>” we chose the word is “pr” for our snippet. When we write “pr” on sublime and then press Tab, our snippet will run.

Then we need to define the language for our snippet on “<scope></scope>”, we create the snippet for the php¬†language so we wrote the “source.php” on the scope.

The last one is the description related to your snippet.

So it’s too easy to create the snippet on sublime as we want.

We will share more snippet that daily used with you.

If you face any issue after create the snippet on sublime write the comment below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s