functions-online

String

Execute and test PHP functions for string manipulation.

addslashes

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).

bin2hex

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

chr

Returns a one-character string containing the character specified by $ascii.

chunk_split

Can be used to split a string into smaller chunks which is useful for e.g. converting base64_encode() output to match RFC 2045 semantics. chunk_split() inserts $end every $chunklen characters in $body.

count_chars

Counts the number of occurrences of every byte-value (0..255) in $string and returns it in various ways.

explode

Returns an array of strings, each of which is a substring of $string formed by splitting it on boundaries formed by the string $delimiter.

html_entity_decode

html_entity_decode() is the opposite of htmlentities() in that it converts all HTML entities to their applicable characters from $string.

htmlentities

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

htmlspecialchars

Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function returns a string with some of these conversions made; the translations made are those most useful for everyday web programming. If you require all HTML character entities to be translated, use htmlentities() instead.

implode

Join array elements with a $glue string.

levenshtein

The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform $str1 into $str2.

In its simplest form the function will take only the two strings as parameter and will calculate just the number of insert, replace and delete operations needed to transform $str1 into $str2.

A second variant will take three additional parameters that define the cost of insert, replace and delete operations. This is more general and adaptive than variant one, but not as efficient.

number_format

This function accepts either one, two, or four parameters (not three):

If only one parameter is given, $number will be formatted without decimals, but with a comma (",") between every group of thousands.

If two parameters are given, $number will be formatted with $decimals decimals with a dot (".") in front, and a comma (",") between every group of thousands.

If all four parameters are given, $number will be formatted with $decimals decimals, $dec_point instead of a dot (".") before the decimals and $thousands_sep instead of a comma (",") between every group of thousands.

ord

Returns the ASCII value of the first character of string. This function complements chr().

parse_str

Parses $str as if it were the query string passed via a URL and sets variables in the current scope.

similar_text

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.

soundex

Soundex keys have the property that words pronounced similarly produce the same soundex key, and can thus be used to simplify searches in databases where you know the pronunciation but not the spelling. This soundex function returns a string 4 characters long, starting with a letter.

str_pad

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.

str_replace

This function returns a string or an array with all occurrences of $search in $subject replaced with the given $replace value.

If you don't need fancy replacing rules (like regular expressions), you should always use this function instead of ereg_replace() or preg_replace().

str_rot13

str_rot13() performs the ROT13 encoding on the $str argument and returns the resulting string. The ROT13 encoding simply shifts every letter by 13 places in the alphabet while leaving non-alpha characters untouched. Encoding and decoding are both done by str_rot13(), passing an encoded string as argument will return the original version.

strip_tags

This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given $str. It uses the same tag stripping state machine as the fgetss() function.

stripos

Returns the numeric position of the first occurrence of $needle in the $haystack string. Unlike strpos(), stripos() is case-insensitive.

stristr

Returns all of $haystack from the first occurrence of $needle to the end. The search is not case sensitive.

strlen

The function strlen() returns the length of the given $string.

strncmp

This function is similar to strcmp(), with the difference that you can specify the (upper limit of the) number of characters from each string to be used in the comparison.

Note that this comparsion is case sensitive.

strpos

Returns the numeric position of the first occurrence of $needle in the $haystack string. Unlike the strrpos() before PHP 5, this function can take a full string as the $needle parameter and the entire string will be used.

strripos

Find position of last occurrence of $needle in the case-insensitive string $haystack. Unlike strrpos(), strripos() is case-insensitive.

strrpos

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.

If $needle is not found, strrpos() returns FALSE.

strstr

Returns part of $haystack string from the first occurrence of $needle to the end of $haystack.

strtolower

Returns $str with all alphabetic characters converted to lowercase.

Note that 'alphabetic' is determined by the current locale. This means that in i.e. the default "C" locale, characters such as umlaut-A (Ä) will not be converted.

strtoupper

Returns $str with all alphabetic characters converted to uppercase.

Note that 'alphabetic' is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted.

strtr

This function returns a copy of $str, translating all occurrences of each character in $from to the corresponding character in $to.

If $from and $to are different lengths, the extra characters in the longer of the two are ignored.

substr

Returns the portion of string specified by the $start and $length parameters.

If $start is non-negative, the returned string will start at the $start'th position in $string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.

substr_count

substr_count() returns the number of times the $needle substring occurs in the $haystack string. Please note that $needle is case sensitive.

Syllable Division

This script, devide string into their syllables. You will recieve an array with all syllables divided. This script is written and tested for german words.

The code was started by PHP-Blogger and was modified in details by myself. There are still some bugs.

trim

This function returns a string with whitespace stripped from the beginning and end of $str. Without the second parameter, trim() will strip these characters:

  • " " (ASCII 32 (0x20)), an ordinary space.
  • "\t" (ASCII 9 (0x09)), a tab.
  • "\n" (ASCII 10 (0x0A)), a new line (line feed).
  • "\r" (ASCII 13 (0x0D)), a carriage return.
  • "\0" (ASCII 0 (0x00)), the NUL-byte.
  • "\x0B" (ASCII 11 (0x0B)), a vertical tab.

ucfirst

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

Note that "alphabetic" is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted.

ucwords

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

The definition of a word is any string of characters that is immediately after a whitespace (These are: space, form-feed, newline, carriage return, horizontal tab, and vertical tab).

vsprintf

Operates as sprintf() but accepts an array of arguments, rather than a variable number of arguments.

wordwrap

Wraps a string to a given number of characters using a string break character.