PHP Strings Cheatsheet


PHP String Functions Cheatsheet

    addcslashes
    -escapes all characters C style

    addslashes
    -escapes some characters with backslashes.

    bin2hex
    -converts a binary string to hexadecimal

    chop
    -removes whitespace from the far right of a string

    chr
    -returns a specified character from a string

    chunk_​split
    -makes smaller chunks out of the specified string

    convert_​cyr_​string
    -used to convert Cyrillic character

    convert_​uudecode
    -used to decode a uuencoded string

    convert_​uuencode
    -used to encode a string with a uuencode algorithm

    count_​chars
    -used to give a count for the number of characters within a string

    crc32
    -used to get the crc32 checksum of a string

    crypt
    -creates a one way hashed password-like string

    echo
    -used for printing

    explode
    -convert a string to an array. Can separate if the string has blank spaces between words or another character like a comma.

    fprintf
    -used to write formatted text to a stream

    get_​html_​translation_​table
    -get html entity translations for htmlspecialchars and htmlentities. Gives a nice readable list in the form of an array.

    hebrev
    -converts text from hebrew

    hebrevc
    -like hebrev function except that it will convert newlines '\n' to "<br>\n".

    hex2bin
    -converts a string from hexadecimal to binary

    html_​entity_​decode
    -decodes from html entities to the actual character.

    htmlentities
    -creates html entities from various characters; like quotes, html and symbols.

    htmlspecialchars_​decode
    -decodes characters to their actual html code.

    htmlspecialchars
    -translates special characters like html, quotes and symbols into special translatable characters.

    implode
    -converts an array into a string. You specify the character you want to use separate the items that came from the array.

    join
    -alias of implode

    lcfirst
    -turns the first character of a string to lower case

    levenshtein
    -used to calculate ditsnaces between 2 strings

    localeconv
    -used to get numeric formatting information

    ltrim
    -removes whitespace from the beginning of a string

    md5_​file
    -used to get a md5 hash from a specified file.

    md5
    -used to create an md5 hash of a particular string.

    metaphone
    -used to get a metaphone key of a string

    money_​format
    -Get a number formatted for a specified currency

    nl_​langinfo
    - a non Windows function that can receive the laguage and locale info. Can pass a constant into the function.

    nl2br
    -changes '\n' to '<br/>'. Useful when going from running a script in the browser vs the Linux command line.

    number_​format
    -specify decimal points in a number

    ord
    -returns the first character in a string as an ascii value.

    parse_​str
    -parses a string into variables. The string that is parsed contains the usual method of writing like var1=value1&var2=value2.

    print
    -prints a string

    printf
    -prints a formatted string

    quoted_​printable_​decode
    -Makes an 8-bit string from a quoted printable string

    quoted_​printable_​encode
    -makes a quoted printable string from an 8-bit string

    quotemeta
    -Returns a string with backslashes around the characters

    rtrim
    -removes whitespace from end of a string

    setlocale
    -used to set locale info

    sha1_​file
    -get the hash value for a file

    sha1
    -create a sha1 string from a specified string. If true, the hash is 20 charaxters; unlike the default 40 characters.

    similar_​text
    -used to calculate the similarity between 2 strings. Matches tghe characters in the first string that are in the second string, including whitespace. Then, divides by total characters.

    soundex
    -used to get the soundex of a string

    sprintf
    -used to return a formatted string

    sscanf
    -used to parse input from string according to the specified format

    str_​getcsv
    -turns a csv into an array

    str_​ireplace
    -find and replace from a string. This is the case insesnitive version of sttr_replace() function.

    str_​pad
    -used to add whitespace or characters to the specified side of the string. By default, it adds whitespcahe to the end of the string. The numerical parameter specifies the total length of the string.

    str_​repeat
    -used to repeat a string the desired amount of times.

    str_​replace
    -find and replace characters from a string.

    str_​rot13
    -transforms string to rot13 version.

    str_​shuffle
    -shuffles all characters to a random position.

    str_​split
    -converts a string to an array. By default, each character is an item in the array. If you add an integer parameter, it will create an array from 0 to the specified number.

    str_​word_​count
    -used to get the word count from a string.

    strcasecmp
    -compares case insensitivity of two strings

    strchr
    -the alias of strstr() function

    strcmp
    -used to compare 2 strings and is case sensitive.

    strcoll
    -string comparison that is locale based

    strcspn
    -compares 2 strings and finds the length of string 1 for which there are no characters from string 2.

    strip_​tags
    -removes html tags. Can alsom specify which pnes you do not want to strip.

    stripcslashes
    -strips backslashes

    stripos
    -find if the string exists in a string. The first parameter is the haystack and second is the needle. Remember that first position is zero. This means you need to compare as identical.  

    stripslashes
    -used to strip backslashes from a string

    stristr
    -the case insensitive version of strstr()

    strlen
    -used to get the length of a string.

    strnatcasecmp
    -case insensitive function that compares strings with a "natural order" algorithm

    strnatcmp
    -compares strings with a "natural order" algorithm

    strncasecmp
    -compares two strings with a desired length.

    strncmp
    -compares 2 strings based on a desired amount of characters

    strpbrk
    -looks for a the desired characters in a string. The new string starts where the first match was made and continues to the end of the string.

    strrchr
    -returns the last occurence of the needle in the haystack and any characters that exist after the last occurrence.

    strrev
    -returns the string with the characters reversed

    strripos
    -finds the position of the last case insensitive occurence of the needle in the haystack.

    strrpos
    -finds the position of the last case sensitive occurence of the needle in the haystack.

    strspn
    -get the length of characters within a string as compared to a mask.

    strstr
    -Look for first occurrence of needle in a haystack. Haystack is the first parameter.

    strtok
    -used to tokenize a string

    strtolower
    -returns the string with all lower case characters

    strtoupper
    -returns the string with all upper case characters

    strtr
    -used to replace substrings

    substr_​compare
    -used to compare 2 strings. Can set how many characters to compare.

    substr_​count
    -find how may times a substring exists in a string

    substr_​replace
    -used to replace a substring with a different set of characters

    substr
    -used to return part of a string

    trim
    -removes whitespace from the beginning and end of a string

    ucfirst
    -makes the first character in a string upper case

    ucwords
    -used to make the first character of each word uppercase

    vfprintf
    -used to write a formatted string to a stream

    vprintf
    -used to output a formatted stream

    vsprintf
    -used to returns a formatted string

    wordwrap
    -wraps a string at a specified length. Can be used to add line breaks at a specific amount of characters.