Convert Boolean Text To Boolean

Strings always evaluate to boolean true unless they have a value that's considered "empty" by PHP.  FILTER_VALIDATE_BOOLEAN provides a solution though:

	$UploadsEnabled = "false";
	$UploadsEnabled = filter_var($UploadsEnabled, FILTER_VALIDATE_BOOLEAN);

Convert Bytes To UInt32

	$handle = fopen("myfile.bin", "rb");
	$Contents = fread($handle, 20); 
	$FileByteArray = unpack("C*",$Contents); 				//<<<Warning the outputted array starts from [1] not [0] !!!!!! Bloody PHP...
	$ByteCount = 1;			//<Yes 1 not 0
	//Get uint32_t value from block of 4 bytes
	$SerialNumber = $FileByteArray[$ByteCount++] << 24;
	$SerialNumber += $FileByteArray[$ByteCount++] << 16;
	$SerialNumber += $FileByteArray[$ByteCount++] << 8;
	$SerialNumber += $FileByteArray[$ByteCount++];




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.