PHP

PHP Logo

PHP (or "PHP: Hypertext Preprocessor") is a widely-used Open Source scripting language that is created specifically for Web development and can be embedded into HTML.

Articles

Using PHP Short Tags
PHP Short Tags refers to '<?' when a full tag is '<?php'. Most PHP installations has short tags support - but there are a few installations that have turned it off. So it is recommended that you don't use the short tags in your app if you plan to distribute it.
Capture the Output of an Included File
It is possible to capture the output of an include to a variable. This is useful for caching and code generation. I found this feature when I was creating a code generation script for IFrame.
Path of the Current File in PHP
There are various methods of find the path of the current file in PHP. But the problem is to find one that is consistent across all servers. The following is a list of the most commonly used methods to find the location of the current file. The definitions are taken from the PHP manual(Predefined Variables) and are modified slightly.
Curl Function in GoDaddy Hosting
Using the Curl Function in GoDaddy Hosting - this is tricky as GoDaddy is using a proxy server.

PHP Scripts

Posting to Twitter Using the load() Function for PHP
Due to the super simple API that's provided by twitter, its very easy to post to Twitter. And thats made even simpler by using the load() function. As simple as this...
PHP Function to Check Domain Availability
This function will check for the availability of the domain you gave as the argument. Note: This script will only work in Linux system - it uses the whois command to do the lookup.
Image Class - GD Wrapper
This is a wrapper class for the GD Library in PHP. You can use this to manipulate images. Please note that you must have GD installed in the server for this class to work as advertised.
joinPath() - Combines Multiple Path Fragments
This function will combine all the path fragments provided as the argument and return the result. joinPath() will use the correct path separator for the current platform.
SqlPager PHP Class
SqlPager PHP class make paging very simple - just provide it with the query to page, and it will do the rest. It uses the LIMIT keyword to do this. Currently, it support only MySQL.
ls() - Return Folder Contents
The ls() function will take a pattern and a folder as the argument and go thru it(recursively if needed)and return the list of all files in that folder.
Functions to Import/Export CSV data
These two function make it very easy to import and export CSV in PHP.
PHP Function to Create URLs - getLink()
getLink() is a function that will make creating URLs much easier. This function expects two arguments - the first argument is the URL and the second one is an array with all the parameters that should be passed with the URL. The function will combine the existing URL with the parameter array and return the resulting URL.
load() Function for PHP - Fetch URL Content

I recently had to develop a small script that will fetch an XML file from the web. All I had to do is download a given URL and read its contents. To my great surprise I found that download the file using my jx Ajax library was much easier than doing it with PHP.

PHP make this very easy by including functions like file_get_contents() that has URL support. Unfortunately, this is a huge security threat - and many servers have disabled this feature in PHP. PHP provide other two method to fetch an URL - Curl and Fsockopen. But to use this I have to write a lot more code. So I decided to create my own function that makes it much more easier.

iFrame PHP Framework
iFrame is my PHP framework - developed for personal use and distributed under the BSD License. I will not recommend using this framework for your projects.
Upload Function
Uploading a file using PHP is not a single step function. To make this easier, I have created a function that will upload a file with just one function call. Just upload('image'); and the file is uploaded! upload() is a function that makes uploading files very easy.
Element Deletion from Array
PHP have a large number of native functions for array operations. When I am coding in javascript, I envy this feature of PHP. Many people have gone to the extend of porting the most needed functions over to javascript. However, you will find that one function is missing in PHP - the remove function for an array element.
Dump() Function - Formated print_r()
The print_r() is a very valuable function for all PHP developers. However, there is two problems with this function -
xml2array() - XML Parser for PHP
xml2array() is a easy to use PHP function that will convert the given XML text to an array in the XML structure. Kind of like my Javascript xml2array() function.
array2json() - Convert PHP arrays to JSON
array2json is a PHP function that will convert the array given as its argument into a JSON string. The created JSON string will be returned. This is very useful in Ajax apps using JSON over XML. If you are using XML, you better off using my xml2array() JavaScript function.
Benchmarking Script - Timer
Time the execution of your script using this simple script.
sql2json() - Converts SQL Results to JSON String
sql2json() converts the result of the given SQL query to its equivalent JSON string.
Query() Function
query() function will accept a query as its argument and return the data in different formats based on the result of the query.

PHP Programs

PHP Watermark Script
This script will let you watermark your photos with ease. It uses the GD library. You'll have to create a PNG image with your watermark and update the script with its location.
Nexty - GTD ToDo List
Nexty is a easy to use GTD tool created in PHP. It can be installed in a local server or in a online web server.
Nexty Demo
A demo of Nexty
Google Sitemap Generator
You can use this script to create the google sitemap XML for your site automatically. The script will recursively visit all files on your site and create a sitemap XML file in the format needed by Google. This site is targeted at sites with static content.

Some PHP Links...

Subscribe to Feed