Skip to main content

Posts

Showing posts with the label PHP Functions

Calculate Number of working days in a month excluding weekends(Saturday and Sunday) using PHP

The below function is used to calculate number of working days in a month. Function Calling: $no_days= rns_countDays ($row['date'],array(0, 6)); Function: function rns_countDays($date, $ignore) {      //echo countDays(array(0, 6), start_date, end_date);     $count = 0;     $ndays=0;     $now=date("Y-m-d");     $month=date("m",strtotime($date));     $year=date("y",strtotime($date));            if($month==date("m") && $year==date('y')) { //Date diff month start date to current date         $from_date = new DateTime($year.'-'.$month.'-01');         $to_date = new DateTime($now);         $days_diff=$from_date->diff($to_date); //echo $days_diff->d;         $ndays=$days_diff->format("%a");         for($i=0;$i<$ndays;$i++){             $modif = $from_date->modify('+1 day');             $weekday = $from_date->format('w');             if(in_array($weekday, $igno

Get current filename with first parameter(Query String) from URL using PHP function

Today eabhyas come up with a Query String function. This function is useful to get the Query String from URL. This Function is used to get current filename with first parameter(Query String) from URL using PHP function . Function: function rns_QueryString_first($incomingURL){     preg_match('/[^&]+/', $incomingURL, $match);     return $outgoingURL = $match[0]; } Example: $path="property_add?id=3&aa=aa&b=123"; define('RNSFIFQ', rns_QueryString_first($path)); echo RNSFIFQ; Output: property_add?id=3

Populate Dropdown List with Array Values in PHP

The below PHP function used to Populate HTML Dropdown List from Array Values. Function : <?php function rnsdrop_Array($arr,$selids,$title='Select'){     print"<option value='0'>".$title."</option>";     foreach($arr as $id =>$name) {     if($selids==$id && $id!=0)         print "<option value=\"".$id."\" selected>".stripslashes($name)."</option>\r\n";     else if($id!=0)         print "<option value=\"".$id."\">".stripslashes($name)."</option>\r\n";     } } ?>   The below example explains how to generate dropdown list with array values using simple PHP function.   Example: <?php $arr=array(0=>'-',1=>'East','West','North','South'); rnsdrop_Array($prop_facing, @$row['prop_facing'],"Select Property Fac