Common Functions Frequently Used In PHP

  No comments


Hundreds of functions provided by PHP as well as thousands of others are available through various additional extensions. These functions are documented in the PHP documentation. However, in varying degrees of development, it now has various naming conventions. The function syntax is as below:

STRING FUNCTIONS
String functions are used to manipulate strings for various needs. Here will be discussed some string functions that are often used in creating a web application program.

AddSlashes
Used to add a backslash(\) character to a string. It is important to use the query string for the database, for example in MySQL. Some of the characters to which the backsearches are added are the quotes of one('), double quoted characters("), backslash(\) and NULL characters.

Syntax:
Addslashes(string)

StripSlashes
Used to remove the backslash(\) character on a string.

Syntax:
String stripslashes(string)

Crypt
Used to encrypt the DES method of a string. This function is often used to shuffle password strings before they are stored in the database. In the use of this crypt function can be added string parameter 'salt'. This 'salt' parameter is added to determine the random basis. The 'Salt' string consists of 2 characters. If the 'salt' string is not added to the crypt function then PHP will determine itself 'salt' the string randomly.

Syntax:
Crypt(string [, salt])

Echo
Used to print the contents of a string or argument.

Syntax:
Echo(string argument1, string argument2, ....)

Explode
Used to break up a string based on a specific separator and insert the result into a variable array.

Syntax:
Explode(string separator, string [, int limit])

Example:
$namahari = "Monday monday on Wednesday thursday saturday";
$days = explode("", $namahari);

Implode
The usefulness of this function is the reverse of the explode function. The implode function is used to generate a string of each element of an array. The resulting string is separated by a predefined string.

Syntax:
Implode(string separator, array)

Strip_Tags
Used to remove HTML tag codes on a string.

Syntax:
Striptags(string [, string tags not omitted])

StrLen
Used to count the number of characters of a string.

Syntax:
Strlen(string)

StrPos
Used to find the first position of a sub string on a string. This function is usually used to search for a sub string within a string.

Syntax:
Strlen(string, sub string)

Str_Repeat
Used to repeat the contents of a string.

Syntax:
Str_repeat(string, int loop count)

StrToLower
Used to convert a string into lowercase.

Syntax:
Strtolower(string)

StrToUpper
Used to convert a string into uppercase(uppercase)

Syntax:
Strtoupper(string)

SubStr
Used to retrieve a sub string with a certain length of a string in a certain position as well.

Syntax:
Substr(string, int position, int position)

Example:
Substr("abcdefg", 0.3); // produces string "abc" substr("abcdefg", 3,2); // generate string "de"

SubStr_Count

Used to count the number of sub strings in a string

Syntax:
Substr_count(string, substring string)

Example:
Substr_count("This is a test", "is"); // returns a value of 2

UCFirst

Used to replace the first character on a string to uppercase.

Syntax:
Ucfirst(string)

UCWords
Used to replace the first character of each word in a string to uppercase.

Syntax:
Ucwords(string)


FUNCTION DATE
Used to retrieve date and time. The result of this function is a string containing the date / time according to the desired format. The known formats in this date function are as follows:



ƒ    a - "am" or "pm" 
ƒ    A - "AM" or "PM" 
ƒ    B - Swatch Internet time 
ƒ    d - day of the month, 2 digits with leading zeros; i.e. "01" to "31" 
ƒ    D - day of the week, textual, 3 letters; i.e. "Fri" 
ƒ    F - month, textual, long; i.e. "January" 
ƒ    g - hour, 12-hour format without leading zeros; i.e. "1" to "12" 
ƒ    G - hour, 24-hour format without leading zeros; i.e. "0" to "23" 
ƒ    h - hour, 12-hour format; i.e. "01" to "12" 
ƒ    H - hour, 24-hour format; i.e. "00" to "23" 
ƒ    i - minutes; i.e. "00" to "59" 
ƒ    I (capital i) - "1" if Daylight Savings Time, "0" otherwise. 
ƒ    j - day of the month without leading zeros; i.e. "1" to "31" 
ƒ    l (lowercase 'L') - day of the week, textual, long; i.e. "Friday" 
ƒ    L - boolean for whether it is a leap year; i.e. "0" or "1" 
ƒ    m - month; i.e. "01" to "12" 
ƒ    M - month, textual, 3 letters; i.e. "Jan" 
ƒ    n - month without leading zeros; i.e. "1" to "12" 
ƒ    s - seconds; i.e. "00" to "59" 
ƒ    S - English ordinal suffix, textual, 2 characters; i.e. "th", "nd" 
ƒ    t - number of days in the given month; i.e. "28" to "31" 
ƒ    T - Timezone setting of this machine; i.e. "MDT" 
ƒ    U - seconds since the epoch 
ƒ    w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) 
ƒ    Y - year, 4 digits; i.e. "1999" 
ƒ    y - year, 2 digits; i.e. "99" 
ƒ    z - day of the year; i.e. "0" to "365" 
ƒ    Z - timezone offset in seconds (i.e. "-43200" to "43200") 




Syntax:
date(string format)

Example:
Date("Y-m-d"); // generates "2001-07-28" date("l, j F Y"); // generate "Saturday, 28 July 2001" date("H: i: s"); // generate "20:15:07"


FUNCTION MAIL
Used to send e-mail to a specific e-mail address.

Syntax:
Mail(destination string, string subject, string contents [, string header]);

Example:
$sender = "From: me@email.com";
$to = "qody@gmail.com";
$subject = "Notice";
$content = "This is an experiment of sending e-mail using PHP";
mail($to, $subject, $content, $sender);

No comments :

Post a Comment