Return last word of string in JavaScript

This function returns last word of your string.
For example, your string = My lucky color will give you the result = color

function get_last_word(str, sep)
{
    var last_word = '';
    if (str != '')
    {
		sep = ( ! sep) ? '-' : sep;
		last_word = str.split(sep).splice(-1)[0];
    }
    return last_word;
}

Continue reading “Return last word of string in JavaScript”

Get last date or total number of days in PHP

Do you want to find out the last date of the month in PHP. Here is a simple way by providing the valid date. It then takes the month from the date provided and returns the result.

1] Example to find out last date of the date provided

$date = '2016-05-05';
echo date('Y-m-t', strtotime($date));

//output:
2016-05-31

Continue reading “Get last date or total number of days in PHP”

In Kohana 3, Setting up server environment

When the website is under development (usually in local) the environment need to be set as ‘development’.. and whereas when you published the website to access by others (usually visible to public) need to be set as ‘production’.

Technique using .htaccess file
For development: In your .htaccess file of your local computer, set environment variable as..

SetEnv KOHANA_ENV development

For production: In your .htaccess file of your live server, set environment variable as..

SetEnv KOHANA_ENV production

Continue reading “In Kohana 3, Setting up server environment”

In Kohana 3, Save session in database

Session usage for native or database adapter is same. Just follow the below 2 steps on saving database session and you’re done.

1] Create database-based session table:

CREATE TABLE IF NOT EXISTS `sessions` (
	`session_id` VARCHAR( 24 ) NOT NULL,
	`last_active` INT UNSIGNED NOT NULL,
	`contents` TEXT NOT NULL,
	PRIMARY KEY ( `session_id` ),
	INDEX ( `last_active` )
) ENGINE = MYISAM ;

Continue reading “In Kohana 3, Save session in database”

List all months and year within date range in PHP

The function to get all months with their year which falls under the date range specified (i.e. your start date and end date).
It uses PHP DateTime Class to get the result and tested with PHP 5.3

	function _daterange_months($start_date, $end_date, $format = 'm-Y')
	{
		$begin	= new DateTime(date('Y-m-01', strtotime($start_date)));
		$end	= new DateTime(date('Y-m-t', strtotime($end_date)));
        $end	= $end->modify( '+1 day' );

        $result		= array();
		$daterange	= new DatePeriod($begin, new DateInterval('P1M'), $end);
		foreach($daterange as $date)
		{
			$result[] = $date->format($format);
		}
        return $result;
	}

Continue reading “List all months and year within date range in PHP”

List all dates within date range in PHP

The function to get all dates which falls under the date range specified (i.e. your start date and end date).
It uses PHP DateTime Class to get the result and tested with PHP 5.3

	function _daterange_days($start_date, $end_date, $format = 'Ymd')
	{
		$begin = new DateTime($start_date);
		$end = new DateTime($end_date);
		$end = $end->modify( '+1 day' );

		$result = array();
		$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
		foreach($daterange as $date)
		{
			$result[] = $date->format($format);
		}
		return $result;
	}

Continue reading “List all dates within date range in PHP”

Hello world!

Welcome… my first post @ blog.ilyaskazi.com

Earlier to this I had many several blogs and unfortunately all are closed now for some reasons.. mainly for uplifting my career in IT. So didn’t had much time to share the things.

Hello world!Now will try putting my best effort to make this live. So keep reading and keep connected!