Skip to content

Instantly share code, notes, and snippets.

@INDIAN2020
Created May 27, 2013 02:31
Show Gist options
  • Select an option

  • Save INDIAN2020/5654895 to your computer and use it in GitHub Desktop.

Select an option

Save INDIAN2020/5654895 to your computer and use it in GitHub Desktop.
php: helperfunctions
<?php
class HelperFunctions
{
/**
* This function is responsible to convert % to double
* @param integer $a
* @return double
*/
public static function isPercentage($a){
if(preg_match('/%/',$a)){
$e=explode('%', $a);
return $e[0]/100;
}else{
return $a;
}
}
/**
* This function to var_dump replica
* @param array $value
* @return array
*/
public static function dump($value){
$out = "<pre>";
$out.= var_dump($value);
$out.= "</pre>";
return $out;
}
/**
* This function responsible to rid of whitespaces and replace with dash
* @param string $string
* @return string
*/
public static function fetch_value($string){
$string = trim($string);
$string = mysql_real_escape_string($string);
$string = stripslashes($string);
$string = preg_replace('/[ _]+/', '-', $string);
return $string;
}
/**
* This is useful to get the dates
* @return array
*/
public static function dateRange()
{
$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d');
$previous_date = date('Y-m-d', strtotime($date .' -1 day'));
$next_date = date('Y-m-d', strtotime($date .' +1 day'));
return array('<a href="?date='.$previous_date.'">Previous</a>','<a href="?date='.$next_date.'">Next</a>');
}
/**
* This will return previous and next dates
* @return string
*/
public static function datePrevious()
{
$arr = list($previous_date,$next_date) = HelperFunctions::dateRange();
return $arr;
}
}
echo (HelperFunctions::datePrevious()[0]);
echo (HelperFunctions::datePrevious()[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment