February 12, 2014

PHP Helper Function: get_function_static()

PHP Helper Function: get_function_static() Description: This function returns the name of calling function. You can specify the $index param to retrieve nth level of calling functions. function get_function_static($bt, $index=0) { if (isset($bt[$index][‘function’])) return $bt[$index][‘function’]; else return false; } Usage $bt = debug_backtrace(); $parent_function = $this->get_function_static($bt, 1);

January 31, 2014

PHP Regular Expressions to Extract Images from HTML Content

PHP Regular Expressions to Extract Images from HTML Content //preg_match_all(‘/<img[^>]+>/i’, $description, $img); //preg_match_all(‘/src=”([^”]*)”/’, $description, $img); preg_match_all(‘@<img.*src=”([^”]*)”[^>/]*/?>@Ui’, $description, $img);

December 27, 2013

PHP – Helper Function – clean_xhtml

PHP – Helper Function – clean_xhtml if ( ! function_exists(‘clean_xhtml’)) { function clean_xhtml($string) { /*$string = preg_replace(‘@<iframe[^>]*?>.*?@siu’, ”,html_entity_decode($string)); $string = preg_replace(‘@<p[^>]*?>.*? @siu’, ”,$string); return $string;*/ $string = ereg_replace(“<[^>]*>”, “”, $string); $string = preg_replace(“@<p[^>]*?>.*? @siu”, ”,$string); return $string; } }

July 8, 2013

PHP Function – Time Difference or Time Ago

PHP Function – Time Difference or Time Ago function _ago($time_to, $time_from = 0) { if($time_from==0) time(); $rtc = 60*60*24; //ROUND THE CLOCK $total_weeks = 52.177457; //ESTIMATE NO. OF WEEKS $years = (int)((($time_from – $time_to)/(7*$rtc))/$total_weeks); $rem = (int)(($time_from-$time_to)-($years * $total_weeks * 7 * $rtc)); $weeks = (int)(($rem)/(7*$rtc)); $days = (int)(($rem)/$rtc) – $weeks*7; $hours = (int)(($rem)/3600) – […]

August 8, 2012

Current Week No. PHP Function

Current Week No. PHP Function if(!function_exists(‘current_week_no’)) { function current_week_no() { $current_date = date(‘Y-m-d’); $date_part = explode(‘-‘, $current_date); $date_part[2] = ’01’; $start_of_month = implode(‘-‘, $date_part); $day_for_first = date(‘N’, strtotime($start_of_month)); $day_for_month = date(‘j’, strtotime($current_date)); $current_month_current_week = floor(($day_for_first + $day_for_month – 1) / 7) + 1; $last_month = (date(‘m’)-1); $week_limit_of_last_month = $last_month*4; $return = $week_limit_of_last_month+$current_month_current_week; return $return; } […]

December 8, 2011

PHP Explode, PHP End, File Name, File Extension

PHP Explode, PHP End, File Name, File Extension if ( ! function_exists(‘file_parts’)) { function file_parts($url,$params=’ext’) { if($params==’ext’) { $parts = explode(‘.’,$url); return end($parts); } elseif($params==’name’) { $parts = explode(‘/’,$url); return end($parts); } else { $parts = explode(‘/’,$url); $file_name_ext = explode(‘.’,end($parts)); $file_name = array_pop($file_name_ext); return implode(‘.’,$file_name); } } }