jareddreyer
10/3/2016 - 3:07 AM

PHP snippets

PHP snippets

<?php

$postvars = str_replace('=', ':', http_build_query($data, null, '&'));
var_dump($postvars);
<?php
/**
    *   format the closing date so it removes -1 minute
    *   ideally this would be in the DB, but the CMS field 
    *   is not using the time component to save using a default value.
    *
    *   @param $date <string>
*/

public function dateConvert ($date) {
    
    $oldDate = strtotime('+23 hours 59 minutes', strtotime($date));
    $newDate = date('m/d/Y H:i', $oldDate);

    $myDateTime = DateTime::createFromFormat('m/d/Y H:i', $newDate);
    $newDateString = $myDateTime->format('d/m/Y H:i');

    return $newDateString;
}
<?php

/**
  *   takes a date and grabs todays date
  *   then does a date difference and converts to month count
  *
  *   @param $date <string>
*/

public function dateConvert ($date)
{
    
  $Tmpdate = str_replace('-', ' ', $date);
    
  $todaysDate = new DateTime("Y");
  $futureDate = new DateTime("Y");
  $futureDate->modify($Tmpdate);
  $interval = date_diff($todaysDate, $futureDate, true);

  $monthCount = $interval->m + ($interval->y * 12);
  
}
$comments = array_map(array($this, 'cleanComments'), $comments);  //using object

//trim array elements and remove quotes
function cleanComments($comment)
{
  return trim($comment, "'" );
}

//OR
// short hand annymous function
$comments = array_map(function($comment) { return trim($comment, "'" ); }, $comments); //trim array elements and remove quotes

//render a default widget
public function JobAdderWidget()
{
  $widget = new JobadderWidget();
  return $widget->renderWith("WidgetHolder");
}