String Functions

There are many string functions for performing operations on the string data. Some methods require additional parameters.

Case Conversion

  • strtolower: Convert string to lowercase
  • strtoupper: Convert string to uppercase
  • ucfirst: Uppercase the first character
  • lcfirst: Lowercase the first character
  • ucwords: Uppercase the first character of each word

Replace or Modify Strings

  • str_replace: Replace all occurrences of the search string
  • str_ireplace: Case-insensitive version of str_replace
  • substr_replace: Replace part of a string with another
  • preg_replace: Perform a regular expression search and replace

String Formatting and Escaping

  • number_format: Format a number with grouped thousands
  • htmlspecialchars: Convert special characters to HTML entities
  • htmlentities: Convert all applicable characters to HTML entities
  • htmlspecialchars_decode: Convert special HTML entities back
  • html_entity_decode: Convert all HTML entities back to characters
  • strip_tags: Remove HTML and PHP tags from a string

String Utilities

  • str_pad: Pad a string to a certain length
  • str_repeat: Repeat a string
  • str_shuffle: Randomly shuffles a string
  • strrev: Reverse a string
  • trim: Strip whitespace (or other characters) from the beginning and end
  • ltrim or rtrim: Strip white spaces from left or right side
  • wordwrap: Wraps a string to a given number of characters

Length and Word Count

  • strlen: Get the length of the string
  • str_word_count: Get the number of words in a string

Concatenation

  • Pre Concatenation: Add prefix to a string
  • Post Concatenation: Add suffix to a string

Special Functions

  • Random Generator: Generates a random string of given length