String Functions

These are the basic string manipulation functions supported by PHP. They are all 8-bit clean, which means that the data they act on does not necessarily have to be straight text. In other words, a string may include any character in the ASCII table including 0. Here are the string functions:

string addslashes(string str)

Escape single quotes, double quotes, and backslash characters in a string with backslashes

string base64_decode(string str)

Decode a string with MIME base-64

string base64_encode(string str)

Encode a string with MIME base-64

string chop(string str)

Remove trailing whitespace

string chr(int ascii)

Convert an ASCII code to a character

string chunk_split(string str [, int chunklen [, string ending]])

Return split line

string convert_cyr_string(string str, string from, string to)

Convert from one Cyrillic character set to another

string crypt(string str [, string salt])

DES-encrypt a string

int ereg(string pattern, string string [, array registers])

Regular expression match

string ereg_replace(string pattern, string string [, array registers])

Replace regular expression

int eregi(string pattern, string string [, array registers])

Case-insensitive regular expression match

string eregi_replace(string pattern, string string [, array registers])

Replace case-insensitive regular expression

string escapeshellcmd(string str)

Escape shell metacharacters

array explode(string separator, string str)

Split a string on the specified string separator

string hebrev(string ...

Get Webmaster in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.