Code Is Poetry

Life is Binary

PHP

All country list in PHP

For one of my PHP works I had to implement and use the array of all countries of the world. So, with the help of net, I created the array. The code in PHP is as follows <?php$countries = array(    'AF' => 'Afghanistan',    'AX' => 'Aland Islands',    'AL' => 'Albania',    'DZ' => 'Algeria',    'AS' => 'American Samoa',    'AD' => 'Andorra',    'AO' =>...

Read more

Binary Tree in PHP

<?php class BinaryNode { public $value; // contains the node item public $left; // the left child BinaryNode public $right; // the right child BinaryNode public function __construct($item) { $this->value = $item; // new nodes are leaf nodes $this->left = null; $this->right = null; } }   // inserting into Binary Tree class BinaryTree { ... public function insert($item) { $node =...

Read more

Php - getting different time of a single day

<?php /* This sets the $time variable to the current hour in the 24 hour clock format */ $time = date("H"); /* Set the $timezone variable to become the current timezone */ $timezone = date("e"); /* If the time is less than 1200 hours, show good morning */ if($time <"12"){ echo "Good morning";} else/* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */ if($time >="12"&& $time...

Read more

html table extending php array object

The code will be as follows:class mahfooz extends ArrayObject{      public function createhtmlTable($array){      $arrayObj = parent::__construct($array);        echo "<table border=1 cellpadding='10'>";    /*** iterate over the array ***/    for($iterator = $this->getIterator();         /*** check if valid...

Read more

Paypal ipn code step by step

You will find in depth about how the IPN of Paypal works in the paypal site itself. Following that source code I have re touched it with addiitonal features like querying mysql database and using php file logging for debugging purpose. Use this ipn code with your caution. You will need paypal sandbox account first along with paypal developer account to implement this IPN.To test this ipn after completing integration whether it works properly or not, you can do it from your created...

Read more

php strtotime function and its usage

It is very important to know what strtotime function does. It can be used in following ways. echo(strtotime("now") . "<br>"); echo(strtotime("3 October 2005") . "<br>"); echo(strtotime("+5 hours") . "<br>"); echo(strtotime("+1 week") . "<br>"); echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>"); echo(strtotime("next Monday") ....

Read more

Creating csv file using php

For report creation it is often necessary to create csv files. It can be done in following way: // output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=data.csv'); // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); // output the column headings fputcsv($output, array('Column 1', 'Column 2', 'Column 3')); //...

Read more

Changing timezone in php

code is as follows:   date_default_timezone_set('Asia/Dhaka'); Full list of timezones are as follows http://www.php.net/manual/en/timezones.php  

Read more

Adding days to a date

It is very simple adding days to dates. Example: $date1 = '2007-03-24'; $latest_date = date("M|j", strtotime("+1 days", strtotime($date1)));

Read more

php How to get parent id rows using iterative fashion

Suppose in database mysql table setup is as follows - id catID parentID catName 1 1 0 location 2 2 0 color 3 3 0 Bangladesh 4 4 3 Dhaka 5 3 3 Rajshahi 6 6 2 Khulna 7 7 2 Comilla Now you want to find the parent category id of Rajshahi. You have to code this as follows- $stack = array(); $parent = 5; while($parent != 0){ $data = (put your mysql...

Read more

Clean URL generator using php

Clean url is necessary for search engine optimization as well as enhancing understanding of that url content even without getting into it. This can be done using php. The code is as follows function clean_url($str) { $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str); $clean = strtolower(trim($clean, '-')); $clean = preg_replace("/[\/_|+ -]+/", '-', $clean); return $clean; } If the string is like "hey! this is a sentence" then the above...

Read more