Random PHP string
February 14th, 2008
I needed to generate a random string in php that did not repeat. This little snippet will generate a random non-repeating 32 character string.
// Generate random 32 character string
$string = md5(time());
PHP number_format function problem
February 5th, 2008
I have been using the php number_function() to format currency values in my code and was recently caught by the thousand separator comma. If you use the function and just specify the the number of decimal places (ie $x = number_format ($y,2) ) then you will get a comma introduced for all numbers above 999.99. This comma will break any maths functions that you might use downstream.
The solution is to specify the decimal point but remove the comma. The format to use to achieve this is $x = $number_format ($y,2,”.”,”") - the empty double quotes tell the number format function to not include the thousand separator comma.
Sphere: Related Content