STRING FUNCTIONS
String functions are used to manipulate the string to a wide range of needs. Here will discuss some string functions are often used in making program web application.
Addslashes
Used to add a backslash character (\) on a string. This important to use the query string to the database, eg in MySQL. Some characters will be added backslahses mark is one character quotes ('), picking two 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 randomize the password string before it is stored in the database. In use of the crypt function can be added to a string parameter 'salt'. Parameter 'salt' was added to determine the basis of randomization. 'Salt' string consists of two character. If the 'salt' string is not added to the PHP crypt function will determine their own 'salt' is a random string.
Syntax:
crypt (string [, salt])
Echo
Used to print the contents of a string or argument.
Syntax:
echo (string argumen1, string argumen2, ....)
Explode
Used to break up a string based on a specific list separator and incorporate the results into an array variable.
Syntax:
explode (string separator, string [, int limit])
Example:
$ Namahari = "week monday tuesday wednesday thursday friday saturday";
$ Days = explode ("", $ namahari);
Implode The usefulness of this function is the opposite than the function explode. Function implode used to generate a string from each of the elements of an array. The resulting string is separated by a string has been determined previously.
Syntax:
implode (string delimiter, array)
Strip_tags
Used to remove the code in a string of HTML tags.
Syntax:
striptags (string [, string tags are not omitted])
Strlen
Used to calculate the number of characters of a string.
Syntax:
strlen (string)
Strpos
Used to find the first position of a sub string in a string. This function usually used to find a sub string within a string.
Syntax:
strlen (string, sub-string)
Str_Repeat
Used to repeat the content of a string.
Syntax:
str_repeat (string, int number of iteration)
StrToLower
Used to convert a string to lowercase (lowercase).
Syntax:
strtolower (string)
StrToUpper
Used to convert a string to uppercase (uppercase)
Syntax:
strtoupper (string)
Substr
Used to retrieve a sub-string with a certain length of a string in the
certain positions as well.
Syntax:
substr (string, int position, int position)
Example:
substr ("abcdefg", 0,3); / / mengasilkan string "abc" substr ("abcdefg", 3,2); / / generate string "de" SubStr_Count
Used to calculate the number of sub string within a string
Syntax:
substr_count (string, string substring)
Example:
substr_count ("This is a test", "is"); / / generate a value of 2
UCFirst
Used to replace the first character in 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)
String functions are used to manipulate the string to a wide range of needs. Here will discuss some string functions are often used in making program web application.
Addslashes
Used to add a backslash character (\) on a string. This important to use the query string to the database, eg in MySQL. Some characters will be added backslahses mark is one character quotes ('), picking two 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 randomize the password string before it is stored in the database. In use of the crypt function can be added to a string parameter 'salt'. Parameter 'salt' was added to determine the basis of randomization. 'Salt' string consists of two character. If the 'salt' string is not added to the PHP crypt function will determine their own 'salt' is a random string.
Syntax:
crypt (string [, salt])
Echo
Used to print the contents of a string or argument.
Syntax:
echo (string argumen1, string argumen2, ....)
Explode
Used to break up a string based on a specific list separator and incorporate the results into an array variable.
Syntax:
explode (string separator, string [, int limit])
Example:
$ Namahari = "week monday tuesday wednesday thursday friday saturday";
$ Days = explode ("", $ namahari);
Implode The usefulness of this function is the opposite than the function explode. Function implode used to generate a string from each of the elements of an array. The resulting string is separated by a string has been determined previously.
Syntax:
implode (string delimiter, array)
Strip_tags
Used to remove the code in a string of HTML tags.
Syntax:
striptags (string [, string tags are not omitted])
Strlen
Used to calculate the number of characters of a string.
Syntax:
strlen (string)
Strpos
Used to find the first position of a sub string in a string. This function usually used to find a sub string within a string.
Syntax:
strlen (string, sub-string)
Str_Repeat
Used to repeat the content of a string.
Syntax:
str_repeat (string, int number of iteration)
StrToLower
Used to convert a string to lowercase (lowercase).
Syntax:
strtolower (string)
StrToUpper
Used to convert a string to uppercase (uppercase)
Syntax:
strtoupper (string)
Substr
Used to retrieve a sub-string with a certain length of a string in the
certain positions as well.
Syntax:
substr (string, int position, int position)
Example:
substr ("abcdefg", 0,3); / / mengasilkan string "abc" substr ("abcdefg", 3,2); / / generate string "de" SubStr_Count
Used to calculate the number of sub string within a string
Syntax:
substr_count (string, string substring)
Example:
substr_count ("This is a test", "is"); / / generate a value of 2
UCFirst
Used to replace the first character in 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)
0 comments:
Post a Comment