Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

}
?>


string uniqid(string prefix, boolean use_lcg)


The uniqid function joins the prefix argument to a random series of numbers and letters,
which are generated based on the system clock. The prefix may be up to 114 characters
long and the unique string is always 13 characters long.


If the optional use_lcg argument is TRUE, nine additional characters will be added to
the end of the return string These characters are generated by the same algorithm used by
the lcg_value function, so they will be a period followed by eight digits. Because the
lcg_value function seeds itself with the process ID, turning on this flag may not actually
add much randomness.


Compare this function to tempnam.


<?
print(uniqid("data"));
?>


Arbitrary-Precision Numbers


Doubles are usually sufficiently precise for any numerical analysis you may wish to
perform. However, PHP offers a way to work with numbers of much higher precision.
The functions in this section use strings to store very long floating-point numbers. They
each use a scale value that is the number of digits to the right of the decimal point. The
scale argument that appears in all of the functions is optional and will override the
default scale. The bcscale function, described in Chapter 11, "Date, Time, and
Configuration Functions," sets the default scale.


These functions are activated when PHP is compiled. They are part of the binary
distribution for windows, but they are not activated by default for other operating
systems. If PHP reports these functions as being unrecognized, you may need to
recompile PHP using the —enable-bcmath option.


string bcadd(string left, string right, integer scale)


The bcadd function adds left to right.


<?
print(bcadd("1.234567890", "9.87654321", 10));
?>

Free download pdf