Sublime snippet for PHP print_r exit Array

Sublime snippet for PHP print_r exit Array

  • 14 July, 2018
  • Renish Khunt
  • Sublime
  • 91

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>';

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.

Hello, ${1:this} is a ${2:snippet}.
    <!-- 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> -->

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

    <content><![CDATA[echo '<pre>';
    <!-- Optional: Tab trigger to activate the snippet -->
    <!-- Optional: Scope the tab trigger will be active in -->
    <!-- Optional: Description to show in the menu -->
    <description>The Coding Stuff Snippet</description>

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.