Coding

9 Most Useful PHP Code Snippets for Developers

Every Programmer and web developer loves talking about their favorite set of snippets and specially PHP developers who spend hours and hours coding websites and application, These guys know how important these snippets are. They are life savers for any serious coder. So before I give out my favorite Snippets, let me give you a brief of what a Snippet is and where one can use it to increase efficiency and saving time.

All Coders who develop website, codes or Application knows the Importance of time. We live in an Age where there is a lot of c competition and to stay ahead, we need to be Productive and need to real quick in our work and results. So if you are a serious coder and want to show your expertise over others you need to have a set of resourceful Snippets that can do a specific task within larger coding projects. A code snippet is nothing but a set of commands that can help you save time fulfilling Laser precision tasks in the quickest possible way.

Let me explain how a Snippet can save you time in the layman language. Say if you are building an E commerce Website. You are building the website from scratch and coding every part of the website. You want to add a feature on the website which helps customers see the value of your products in Dollars, Euros and Yen. If you sit and start coding this on your website it can be a hell of a task. However a Format currency Snippet can do this task for you within a few minutes. Hence, because Snippets are so important every coder keeps a set of his favorites very close to his heart. Here my set of Code Snippets for PHP Developers.

 

1) Whois query using PHP

Using this code you can get whois information for a particular domain. Put a domain name as a parameter and display all the information about domain. Get the code below-

2) Text messaging with PHP using the TextMagic API

TextMagic introduce an powerful API that help to provide a way to send SMS to cell phones easily. If you want to use this API in your project, have to purchase, its paid service. The Code is below-

3) Get info about your memory usage

Using this code you can know about the uses RAM ( memory) on your server.

4) Display source code of any webpage

If you want to get source code of any web pages, change the URL on 2nd line and display the source code of any webpage.

5) Create data uri’s

by using this code you can create data Uri’s, its very useful for embadding images into HTML/CSS to save on HTTp request.

6) Detect location by IP

This code script helps to find out the specific IP, just type IP on place of parameter in function and detect the location easily.

    • City : ([^<]*)

 

}i’, $content, $regs) ) { $city = $regs[1]; } if ( preg_match(‘{

    • State/Province : ([^<]*)

 

}i’, $content, $regs) ) { $state = $regs[1]; } if( $city!=” && $state!=” ){ $location = $city . ‘, ‘ . $state; return $location; }else{ return $default; } }

7) Detect browser language

Detect the browser language using the code script easily.

8) Check if server is HTTPS

With this script, you can know about that your server is HTTPS or not.

9) Generate CSV file from a PHP array

This function helps to generate a .csv file from PHP array. Get the script below-

Popular Posts


To Top