Category : "PHP"

Php tutorials

40+ Useful Php tips for beginners – Part 1

In this series we are going to look into some useful tips and techniques that can be used to improve and optimise your php code. Note that these php tips are meant for beginners and not those who are already using mvc frameworks etc. The Techniques 1. Do not use relative paths , instead define a ROOT path Its quite common to see ...

Execute shell commands in PHP

Like any other language php applications often need to execute system commands like they are run from the terminal/console/commandline. Php has multiple functions to do this task. Lets take a look at each of these 1. system "system() is just like the C version of the function in that it executes the given command and outputs the result. The system() call also ...

Php get list of locales installed on system

On linux , the list of locales installed on the system can be fetched through the terminal command locale -a : $ locale -a C C.UTF-8 en_AG en_AG.utf8 en_AU.utf8 en_BW.utf8 en_CA.utf8 en_DK.utf8 en_GB.utf8 en_HK.utf8 en_IE.utf8 en_IN en_IN.utf8 en_NG en_NG.utf8 en_NZ.utf8 en_PH.utf8 en_SG.utf8 en_US.utf8 en_ZA.utf8 en_ZM en_ZM.utf8 en_ZW.utf8 es_AR.utf8 es_BO.utf8 es_CL.utf8 es_CO.utf8 es_CR.utf8 es_DO.utf8 es_EC.utf8 es_ES.utf8 es_GT.utf8 es_HN.utf8 es_MX.utf8 es_NI.utf8 es_PA.utf8 es_PE.utf8 es_PR.utf8 es_PY.utf8 es_SV.utf8 es_US.utf8 es_UY.utf8 es_VE.utf8 hi_IN hi_IN.utf8 nl_AW nl_AW.utf8 nl_BE.utf8 nl_NL.utf8 POSIX si_LK si_LK.utf8 zh_CN.utf8 zh_SG.utf8 Now this command can be used inside php to get the list. Along with this list we can also add some information like language name and country name using a list of countries and languages. Here is a list ...

Php script to fetch whois information of ip address

Whois information of ip addresses IP addresses are in the form of a.a.a.a where each letter is a number from 0-255. You would be happy to know that every ip address has some information associated to it. For example which isp or organisation has been allotted that ip address and where is that organisation located. This in turn tells the location ...

Quick Tip: Getting the Next and Previous Items or Posts

It is a common requirement in lots of projects to fetch the next and previous items or posts and display a link to them on every item or post page. Getting the previous and next item can be quite tricky especially if they need to be user-specific, although it is very easy. I'll show you how - function nextItem($item_id) { ...

Disqus Comments Importer Script in PHP

Disqus is a great commenting platform that does it's job really well. Many people use it these days because writing your own commenting system is a tedious and hard work whereas a solution like Disqus or Livefyre makes the entire commenting process a breeze with features like social logins, many levels of nesting, easy replying, quick and realtime commenting, easy ...

Convert simplexml object to array in php

The simplexml extension of php is quite simple and easy to use when it comes to parsing "well-formatted" xml files. Well formatted means , xml that is not broken or does not have too many errors. One of the most handy functions of this extension is simplexml_load_string. Here is an example : <?php $xml = '<?xml version="1.0" encoding="UTF-8"?> <resultset> <row> ...

Php : create pdf from html using mpdf

MPDF Many php applications need to create pdf of documents like invoice , receipt and even id card etc. In this article we shall create a pdf invoice using the mpdf pdf creation library. Mpdf is made in php without any other external library. Mpdf parses css much better than any other free pdf libraries like tcpdf and creates pdf files ...

Code a network packet sniffer in PHP

Example of a packet sniffer is Wireshark. Packet sniffers pick up the packets going in and out of a system and analyse them and present them to user for further analysis. In this post we are going to code a simple packet sniffer in php. The basic theory this packet sniffer is that , raw packets can sniff without much effort ...

Php get zip error message from error number

Php functions like zip_open return an error number if they fail. To get the corresponding error message from the error number , use the following function. function zip_error_message($errno) { // using constant name as a string to make this function PHP4 compatible $zipFileFunctionsErrors = array( 'ZIPARCHIVE::ER_MULTIDISK' => 'Multi-disk zip archives not supported.', 'ZIPARCHIVE::ER_RENAME' => 'Renaming temporary file failed.', 'ZIPARCHIVE::ER_CLOSE' => 'Closing zip archive failed', 'ZIPARCHIVE::ER_SEEK' => ...



Connect with us