O'Reilly logo

PHP Pocket Reference by Rasmus Lerdorf

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

string decrypt(string data, int type, string key)

Decrypt string with key using algorithm type (converse of encrypt( ))

string encrypt(string data, int type, string key)

Encrypts string with key using algorithm type (converse of decrypt( ))

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

POSIX-style regular expression match

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

Replace pattern in a string using a POSIX-style regular expression

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

Case-insensitive POSIX-style regular expression match ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required