Thursday, July 29, 2010

Removing special characters from a string using php

$str = '"!@#$%^&*()MyTest\'_+-|/\/{}[];:<,>.?';
$tempVar = preg_replace('/[^a-zA-Z0-9]*/','',$str);
echo $tempVar;

Wednesday, July 21, 2010

get start and end date according given date and duration

function getEndStartDate($date, $duration) {//date format yyyy-mm-dd
$date_time = strtotime( $date );

$date_start_time = mktime( 0, 0, 0, date('m', $date_time), date('d', $date_time), date( 'Y', $date_time ) );
$date_start = date( 'Y-m-d 00:00:00', $date_start_time );
$date_end = date( 'Y-m-d 23:59:59', strtotime( '+'.$duration.' month -1 day', $date_start_time ) );

return array( 'date_start' => $date_start, 'date_end' => $date_end );}