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++];

 

 

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *