PHP String Functions

EditRocket provides the following information on String functions in the PHP source code builder.

string addcslashes ( string $str , string $charlist ) - Returns a string with backslashes before characters that are listed in charlist parameter.

string addslashes ( string $str ) - Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote (), backslash (\) and NUL (the NULL byte).

string bin2hex ( string $str ) - Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first.

-

string chr ( int $ascii ) - Returns a one-character string containing the character specified by ascii.

string chunk_split ( string $body [, int $chunklen [, string $end ]] ) - Can be used to split a string into smaller chunks which is useful for e.g.

string convert_cyr_string ( string $str , string $from , string $to ) - Converts from one Cyrillic character set to another.

string convert_uudecode ( string $data ) - convert_uudecode() decodes a uuencoded string.

string convert_uuencode ( string $data ) - convert_uuencode() encodes a string using the uuencode algorithm.

mixed count_chars ( string $string [, int $mode ] ) - Counts the number of occurrences of every byte-value (0..255) in string and returns it in various ways.

int crc32 ( string $str ) - Generates the cyclic redundancy checksum polynomial of 32-bit lengths of the str. This is usually used to validate the integrity of data being transmitted.

string crypt ( string $str [, string $salt ] ) -

void echo ( string $arg1 [, string $... ] ) - echo() is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo() (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo(), the parameters must not be enclosed within parentheses.

array explode ( string $delimiter , string $string [, int $limit ] ) - Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.

int fprintf ( resource $handle , string $format [, mixed $args [, mixed $... ]] ) - Write a string produced according to format to the stream resource specified by handle.

array get_html_translation_table ([ int $table [, int $quote_style ]] ) -

string hebrev ( string $hebrew_text [, int $max_chars_per_line ] ) - Converts logical Hebrew text to visual text.

string hebrevc ( string $hebrew_text [, int $max_chars_per_line ] ) -

string html_entity_decode ( string $string [, int $quote_style [, string $charset ]] ) -

string htmlentities ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] ) -

-

string htmlspecialchars_decode ( string $string [, int $quote_style ] ) -

string implode ( string $glue , array $pieces ) - Join array elements with a glue string.

-

-

array localeconv ( void ) - Returns an associative array containing localized numeric and monetary formatting information.

string ltrim ( string $str [, string $charlist ] ) - Strip whitespace (or other characters) from the beginning of a string.

string md5 ( string $str [, bool $raw_output ] ) -

string md5_file ( string $filename [, bool $raw_output ] ) -

string metaphone ( string $str [, int $phones ] ) - Calculates the metaphone key of str.

string money_format ( string $format , float $number ) - money_format() returns a formatted version of number. This function wraps the C library function strfmon(), with the difference that this implementation converts only one number at a time.

string nl2br ( string $string ) - Returns string with '
' inserted before all newlines.

string nl_langinfo ( int $item ) - nl_langinfo() is used to access individual elements of the locale categories.

-

int ord ( string $string ) - Returns the ASCII value of the first character of string.

void parse_str ( string $str [, array &$arr ] ) - Parses str as if it were the query string passed via a URL and sets variables in the current scope.

int print ( string $arg ) - Outputs arg.

int printf ( string $format [, mixed $args [, mixed $... ]] ) -

string quoted_printable_decode ( string $str ) -

string quotemeta ( string $str ) - Returns a version of str with a backslash character (\) before every character that is among these:\ + * ? [ ^ ] ( $ )

string rtrim ( string $str [, string $charlist ] ) - This function returns a string with whitespace stripped from the end of str.

string setlocale ( int $category , string $locale [, string $... ] ) -

string sha1 ( string $str [, bool $raw_output ] ) -

string sha1_file ( string $filename [, bool $raw_output ] ) -

int similar_text ( string $first , string $second [, float &$percent ] ) - This calculates the similarity between two strings as described in Oliver [1993]. Note that this implementation does not use a stack as in Oliver's pseudo code, but recursive calls which may or may not speed up the whole process. Note also that the complexity of this algorithm is O(N**3) where N is the length of the longest string.

string soundex ( string $str ) - Calculates the soundex key of str.

string sprintf ( string $format [, mixed $args [, mixed $... ]] ) - Returns a string produced according to the formatting string format.

-

mixed str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) - This function returns a string or an array with all occurrences of search in subject (ignoring case) replaced with the given replace value.

string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] ) - This functions returns the input string padded on the left, the right, or both sides to the specified padding length. If the optional argument pad_string is not supplied, the input is padded with spaces, otherwise it is padded with characters from pad_string up to the limit.

string str_repeat ( string $input , int $multiplier ) - Returns input repeated multiplier times.

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) - This function returns a string or an array with all occurrences of search in subject replaced with the given replace value.

string str_rot13 ( string $str ) - Performs the ROT13 encoding on the str argument and returns the resulting string.

string str_shuffle ( string $str ) -

array str_split ( string $string [, int $split_length ] ) - Converts a string to an array.

mixed str_word_count ( string $string [, int $format [, string $charlist ]] ) - Counts the number of words inside string. If the optional format is not specified, then the return value will be an integer representing the number of words found. In the event the format is specified, the return value will be an array, content of which is dependent on the format. The possible value for the format and the resultant outputs are listed below.

int strcasecmp ( string $str1 , string $str2 ) - Binary safe case-insensitive string comparison.

-

int strcmp ( string $str1 , string $str2 ) -

int strcoll ( string $str1 , string $str2 ) -

int strcspn ( string $str1 , string $str2 [, int $start [, int $length ]] ) - Returns the length of the initial segment of str1 which does not contain any of the characters in str2.

string strip_tags ( string $str [, string $allowable_tags ] ) - This function tries to return a string with all HTML and PHP tags stripped from a given str.

string stripcslashes ( string $str ) - Returns a string with backslashes stripped off. Recognizes C-like \n, \r ..., octal and hexadecimal representation.

int stripos ( string $haystack , string $needle [, int $offset ] ) -

string stripslashes ( string $str ) - Un-quotes a quoted string.

string stristr ( string $haystack , string $needle , bool $before_needle ) - Returns all of haystack from the first occurrence of needle to the end.

int strlen ( string $string ) - Returns the length of the given string.

int strnatcasecmp ( string $str1 , string $str2 ) - This function implements a comparison algorithm that orders alphanumeric strings in the way a human being would.

int strnatcmp ( string $str1 , string $str2 ) - This function implements a comparison algorithm that orders alphanumeric strings in the way a human being would, this is described as a natural ordering. Note that this comparison is case sensitive.

int strncasecmp ( string $str1 , string $str2 , int $len ) -

int strncmp ( string $str1 , string $str2 , int $len ) -

string strpbrk ( string $haystack , string $char_list ) - strpbrk() searches the haystack string for a char_list.

int strpos ( string $haystack , mixed $needle [, int $offset ] ) - Returns the numeric position of the first occurrence of needle in the haystack string.

string strrchr ( string $haystack , string $needle ) - This function returns the portion of haystack which starts at the last occurrence of needle and goes until the end of haystack.

string strrev ( string $string ) - Returns string, reversed.

int strripos ( string $haystack , string $needle [, int $offset ] ) - Find position of last occurrence of a case-insensitive string in a string.

int strrpos ( string $haystack , string $needle [, int $offset ] ) - Returns the numeric position of the last occurrence of needle in the haystack string. Note that the needle in this case can only be a single character in PHP 4. If a string is passed as the needle, then only the first character of that string will be used.

int strspn ( string $str1 , string $str2 [, int $start [, int $length ]] ) - Finds the length of the initial segment matching mask.

string strstr ( string $haystack , string $needle , bool $before_needle ) - Returns part of haystack string from the first occurrence of needle to the end of haystack.

-

string strtolower ( string $str ) - Returns string with all alphabetic characters converted to lowercase.

string strtoupper ( string $string ) - Returns string with all alphabetic characters converted to uppercase.

-

string substr ( string $string , int $start [, int $length ] ) - Returns the portion of string specified by the start and length parameters.

int substr_compare ( string $main_str , string $str , int $offset [, int $length [, bool $case_insensitivity ]] ) - substr_compare() compares main_str from position offset with str up to length characters.

int substr_count ( string $haystack , string $needle [, int $offset [, int $length ]] ) - substr_count() returns the number of times the needle substring occurs in the haystack string. Please note that needle is case sensitive.

mixed substr_replace ( mixed $string , string $replacement , int $start [, int $length ] ) - substr_replace() replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement.

string trim ( string $str [, string $charlist ] ) - This function returns a string with whitespace stripped from the beginning and end of str.

string ucfirst ( string $str ) - Returns a string with the first character of str capitalized, if that character is alphabetic.

string ucwords ( string $str ) - Returns a string with the first character of each word in str capitalized, if that character is alphabetic.

int vfprintf ( resource $handle , string $format , array $args ) - Write a string produced according to format to the stream resource specified by handle.

int vprintf ( string $format , array $args ) -

string vsprintf ( string $format , array $args ) -

string wordwrap ( string $str [, int $width [, string $break [, bool $cut ]]] ) - Wraps a string to a given number of characters using a string break character.