Junal on the run

Some interesting PHP functions…

Posted on: February 9, 2008

Recently, I have studied three types of PHP functions and they are: String functions, Date functions and Array functions. I have noted down some functions that were interesting. Well, PHP got thousands of built in functionality and I guess this is what makes PHP great. So, let’s have a look at some interesting functions from my collection.

String functions:

strpbrk ()

–          Search a string for any of a set of characters

Example :

$text = ‘Junal is studying php functions’;

echo strpbrk($text, ‘s’);
What will be the output? Well its will output: “studying php function”, because‘s’ is matched first.


–          This will reverse the given string


echo strrev(“junal likes to be lost”);

output : “tsol eb ot sekil lanuj” – funny eh ?


–          Tokenizing a string

–          Example :

$string = “Junal is being tokenized”;

$tok = strtok($string, ” \n\t”);

while ($tok !== false) {

echo “Word=$tok<br />”;

$tok = strtok(” \n\t”);


Output :



–          Ahh ! This is one of the most interesting and needy one that I used currently one of out facebook application, it uppercase the first letter of first word!


$string = ‘junal rahman’;

echo ucfirst($string);

output : “Junal rahman”

ok this above function make first letter of first word uppercase right. How about if we want all word’s first letter to be uppercase? Simple! We just have to use ucwords() function !

Date Functions:

Well, among all date functions I found one date function interesting 🙂


–          Format a local time/date as integer


$timestamp = strtotime(‘9th February 2008’);

echo idate(‘m’, $timestamp);

Output: “2”

Array Functions


–          Computes the difference of arrays.

–          Example :

$array1 = array(“a” => “junal”, “anupom”, “manzil”, “ahsan”);

$array2 = array(“b” => “junal”, “anupom”, “manzil”);

$result = array_diff($array1, $array2);


output : “ahsan”

array_key_exists ()

–          Checks if the given key or index exists in the array

array_multisort ()

I used this function in several occasions. Very handy function to sort the multiple arrays. It does a lot of help when we want to sort an array by rank/number.


–          Calculate the product of values in an array


$a = array (2, 4, 6, 8);

echo $a;

output :” 384″

natcasesort ()

–           Sort an array using a case insensitive “natural order” algorithm

range ()

–          Create an array containing a range of elements

Well that’s all! After studying these array functions, I have found another interesting thing about ArrayObject.

$array = array(‘1’ => ‘one’,

‘2’ => ‘two’,

‘3’ => ‘three’);

$arrayobject = new ArrayObject($array);

Excellent stuff! By the way, I have to go now. There are thousands thing I don’t know about PHP. Have to get idea about them, have to run ….

Reference : PHP manual.

3 Responses to "Some interesting PHP functions…"

Nice post….thanks
Please visit this blog for learn more PHP scripts….

as salamoalaikom amer name balasi


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

View Junal Rahman's profile on LinkedIn
Subscribe to me on FriendFeed

Follow Me on Twitter


My photos

Blog Stats

  • 424,735 hits
%d bloggers like this: