String Functions

PHP has several built-in functions for text processing and the manipulation of strings.

A list of PHP string and text processing functions can be found in the table below:

String Functions

explode()
Splits a given string by a delimiter and returns an array of the substrings produced.
hex2bin()
Converts a string of hexadecimal values to its binary representation.
implode()
Joins the elements of an array to form a new string
ltrim()
Trims whitespace or specific characters from the left side of a given string.
rtrim()
Removes whitespace or other predefined characters from the right side of a string.
sprintf()
Returns a string with a specified formatting.
str_repeat()
Returns a string with occurrences of a specified substring repeated a specified number of times.
str_replace()
Returns a string with occurrences of a specified substring replaced by another string.
str_shuffle()
Randomly shuffles a string.
strlen()
Returns the number of bytes in a given string.
substr()
Returns a portion of a specified string.

All contributors

Looking to contribute?

Learn PHP on Codecademy