• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 16. PHP > String Functions

16.25. 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 str, int max_chars_per_line)

Convert logical Hebrew text to visual text


string hebrevc(string str, int max_chars_per_line)

Convert logical Hebrew text to visual text with newline conversion


string htmlentities(string str)

Convert all applicable characters to HTML entities


string htmlspecialchars(string str)

Convert special characters to HTML entities


string implode(array src, string glue)

Join array elements into a string


string join(array src, string glue)

Join array elements into a string


string ltrim(string str)

Strip whitespace from the beginning of a string


string md5(string str)

Calculate the md5 hash of a string


string nl2br(string str)

Convert newlines to HTML line breaks


int ord(string character)

Return the ASCII value of character


void parse_str(string str)

Parse the string into variables


void print(string str)

Output a string


int printf(string format, mixed args, ...)

Output a formatted string


string quoted_printable_decode(string str)

Convert a quoted-printable string to an 8-bit string


string quotemeta(string str)

Quote metacharacters


string rawurldecode(string str)

Decode URL-encoded strings


string rawurlencode(string str)

URL-encode according to RFC-1738


string rtrim(string str)

Remove trailing whitespace (alias for chop() function)


string setlocale(string category, string locale)

Set locale information


int similar_text(string str1, string str2 [, double percent])

Calculate the similarity between two strings


string soundex(string str)

Calculate the soundex key of a string


array split(string pattern, string string [, int limit])

Split string into array by regular expression


string sprintf(string format, mixed args, -)

Return a formatted string


string sql_regcase(string string)

Make regular expression for case-insensitive match


string str_replace(string needle, string str, string haystack)

Replace all occurrences of needle in haystack with str


int strcasecmp(string str1, string str2)

Binary-safe, case-insensitive string comparison


string strchr(string haystack, string needle)

Find the last occurrence of a character in a string


int strcmp(string str1, string str2)

Binary safe string comparison


int strcspn(string str1, string str2)

Find length of initial segment not matching mask


string stripslashes(string str)

Unquote string quoted with addslashes()


string stristr(string haystack, string needle)

Find first occurrence of a string within another, case-insensitive


int strlen(string str)

Get string length


int strpos(string haystack, string needle)

Find position of first occurrence of a string


string strrchr(string haystack, string needle)

Find last occurrence of a character in a string


string strrev(string str)

Reverse a string


int strrpos(string haystack, string needle)

Find position of last occurrence of a character in a string


int strspn(string str1, string str2)

Find length of initial segment-matching mask


string strstr(string haystack, string needle)

Find first occurrence of a string


string strtok(string str, string token)

Tokenize string


string strtolower(string str)

Make a string lowercase


string strtoupper(string str)

Make a string uppercase


string strtr(string str, string from, string to)

Translate certain characters


string substr(string str, int start, int length)

Return part of a string


string trim(string str)

Strip whitespace from the beginning and end of a string


string ucfirst(string str)

Make a string's first character uppercase


string ucwords(string str)

Uppercase the first character of every word in a string


string uniqid(string prefix)

Generate a unique ID


string urldecode(string str)

Decode URL-encoded string


string urlencode(string str)

URL-encode a string


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint