PHP Function: Built-in Functions part 7
Here are yet more Built-in Functions,
Mail Function
If your server has access to sendmail or an SNMP gateway the mail() function sends mail to a specified recipient. Its syntax is
mail(“recipient”, “subject”, “message”, “mail headers”);
For example, the following code sends mail to techsoftcenter@techsoftcenter.com with the subject of “Great Site” and a message body saying “Techsoftcenter.com Is a cool site!”. The “From:” line is part of the additional mail headers.
mail(“techsoftcenter@techsoftcenter.com”, “Great Site”, “Techsoftcenter.com is a cool site!”, “From: youremail@yourdomain.com “);
Mathmatical Functions
ceil()
The ceil() function rounds a fraction up to the next higher integer. Its syntax is
ceil(number);
decbin() and bindec()
The decbin() and bindec() functions convert decimal numbers to binary numbers, and binary numbers to decimal numbers. The syntax of these functions is
decbin(number);
bindec(number);
dechex() and hexdec()
The dechex() and hexdec() functions convert decimal numbers to hexadecimal numbers, and hexadecimal numbers to decimal numbers, respectively. The syntax of these functions is
dechex(number);
hexdec(number);
decoct() and octdec()
The decoct() and octdec() functions convert decimal numbers to octal numbers, and octal numbers to decimal numbers, respectivly. The syntax of these functions is
decoct(number);
octdec(number);
floor()
The floor() function rounds a fraction down to the next lower integer. Its syntax is
floor(number);
number_format()
The number_format() function returns the formatted version of specified number. Its syntax is
number_format(“number”, “decimals”, “dec_point”, “thosands_sep”);
For example, to return a formatted version of the number 12156688, with two decimal places and a comma seperating each group of thousands, use
echo number_format(“12156688″,”2″,”.”,”,”,”,”);
The result is 12,156,688.00
If only a number is provided, the deault formatting does not use a decimal point and puts a comma between ever group of thousands.
pow()
The pos() function returns the value of a given number, raised to the power of a given exponet. Its syntax is
pow(number, exponent);
round()
The round() function rounds a fraction to the next higher or next lower integer. Its syntax is
round(number);
sqrt()
The sqrt() function returns the square root of a given number. Its syntax is
sqrt(number);
srand()
The srand() function provides the random number generator with a set of possible values. Its syntax is
srand(seed);
A common practice is to seed the random number generator by using a number of microseconds:
srand((double)microtime()*1000000);