Convert to int

$Value = intval($Something);    //integer value of value on success, or 0 on failure. Empty arrays return 0, non-empty arrays return 1.

Formatting Numeric Values

Leading Zeros

//Format to 8 digits with leading zeros if necessary
  $MyString = sprintf('%08d', 123456);

Decimal Places

//Force to 2 decimal places
  $MyString = number_format("6.3",2);  //Will display 6.30

Displaying Date And Time

Current Date and Time
   echo date("Y-m-d H:i:s");

   echo date("l dS of F Y h:i:s A");

Values you use: click here

Get hours now
	$TimeNowHours = date('H');
From A String Variable (e.g. a MySQL result)
  $LastCheckIn = strtotime($result1['LastCheckIn']);

  $LastCheckIn = date("Y-m-d H:i:s", strtotime($LastCheckIn));

  echo date("j M g:i a", strtotime($result1['received_date']));	
Display as UTC
$DisplayDate = date("Y-m-d H:i:s", strtotime($DateTimeValue));  

Values you use: click here

Display Value As Hex

	echo 'My value 0x' . sprintf("%02X", $MyValue);		//Display with 2 hex characters (or more if needed to display it)
	echo 'My value 0x' . sprintf("%08X", $MyValue);		//Display with 8 hex characters (or more if needed to display it)

Or the simpler dechex() method but without forcing the number of characters:

	echo "[" . dechex($FileByteArray[1]) . "]";
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.