Jump to: navigation, search

PHP String Functions

From w3cyberlearnings
# Function Example Description
1 addcslashes addcslashes (string,charlist ) Returns a string with backslashes before characters that are listed in charlist parameter.
2 addslashes addslashes (string) add a backslash to any single quotes, double quotes, backslash, and NULL.
3 bin2hex bin2hex ( string) convert binary data into hexadecimal.
4 chop string chop(string) remove white space on the right end of a string
5 chr string chr ( int $ascii ) returns a character from ASCII value.
6 chunk_split chunk_split(string,length,end) splits a string into parts
7 convert_cyr_string string convert_cyr_string ( string $str , string $from , string $to ) Convert from one Cyrillic character set to another
8 convert_uudecode string convert_uudecode ( string $data ) Decode a uuencoded string
9 convert_uuencode string convert_uuencode ( string $data ) Uuencode a string using Uuencode algorithm
10 count_chars mixed count_chars ( string $string [, int $mode = 0 ] ) Return information about characters used in a string
11 crc32 int crc32 ( string $str ) Calculates the crc32 polynomial of a string
12 crypt string crypt ( string $str [, string $salt ] ) One-way string hashing
13 echo void echo ( string $arg1 [, string $... ] ) Output one or more strings
14 explode array explode ( string $delimiter , string $string [, int $limit ] ) Split a string by string
15 fprintf int fprintf ( resource $handle , string $format [, mixed $args [, mixed $... ]] ) Write a formatted string to a stream
16 get_html_translation_table ENT_HTML5) Returns the translation table used by htmlspecialchars() and htmlentities()
17 hebrev string hebrev ( string $hebrew_text [, int $max_chars_per_line = 0 ] ) Convert logical Hebrew text to visual text
18 hebrevc string hebrevc ( string $hebrew_text [, int $max_chars_per_line = 0 ] ) Convert logical Hebrew text to visual text with newline conversion
19 hex2bin string hex2bin ( string $data ) Decodes a hexadecimally encoded binary string
20 html_entity_decode $b = html_entity_decode($a) Convert all HTML entities to their applicable characters
21 htmlentities echo htmlentities($str) Convert all applicable characters to HTML entities
22 htmlspecialchars_decode echo htmlspecialchars_decode($str) Convert special HTML entities back to characters
23 htmlspecialchars $new = htmlspecialchars("Test", ENT_QUOTES) Convert special characters to HTML entities
24 implode string implode ( string $glue , array $pieces ) Join array elements with a string
25 join $comma_separated = join(",", $array) Alias of implode()
26 lcfirst string lcfirst ( string $str ) Make a string's first character lowercase
27 levenshtein int levenshtein ( string $str1 , string $str2 ) Calculate Levenshtein distance between two strings
28 localeconv array localeconv ( void ) Returns an associative array containing localized numeric and monetary formatting information
29 ltrim string ltrim ( string $str [, string $charlist ] ) Strip whitespace (or other characters) from the beginning of a string
30 md5_file string md5_file ( string $filename [, bool $raw_output = false ] ) Calculates the md5 hash of a given file
31 md5 string md5 ( string $str [, bool $raw_output = false ] ) Calculate the md5 hash of a string
32 metaphone string metaphone ( string $str [, int $phonemes = 0 ] ) Calculate the metaphone key of a string
33 money_format string money_format ( string $format , float $number ) Formats a number as a currency string
34 nl_langinfo string nl_langinfo ( int $item ) Query language and locale information
35 nl2br string nl2br ( string $string [, bool $is_xhtml = true ] ) Inserts HTML line breaks before all newlines in a string
36 number_format string number_format ( float $number [, int $decimals = 0 ] ) Format a number with grouped thousands
37 ord int ord ( string $string ) Returns the ASCII value of the first character of string
38 parse_str void parse_str ( string $str [, array &$arr ] ) Parses the string into variables
39 print print("Hello World") Output a string
40 printf printf("%d", "17,999") Output a formatted string
41 quoted_printable_decode string quoted_printable_decode ( string $str ) Convert a quoted-printable string to an 8 bit string
42 quoted_printable_encode string quoted_printable_encode ( string $str ) Convert a 8 bit string to a quoted-printable string
43 quotemeta string quotemeta ( string $str ) Quote meta characters
44 rtrim string rtrim ( string $str [, string $charlist ] ) Strip whitespace (or other characters) from the end of a string
45 setlocale string setlocale ( int $category , array $locale ) Set locale information
46 sha1_file string sha1_file ( string $filename [, bool $raw_output = false ] ) Calculate the sha1 hash of a file
47 sha1 string sha1 ( string $str [, bool $raw_output = false ] ) Calculate the sha1 hash of a string
48 similar_text int similar_text ( string $first , string $second [, float &$percent ] ) Calculate the similarity between two strings
49 soundex string soundex ( string $str ) Calculate the soundex key of a string
50 sprintf string sprintf ( string $format [, mixed $args [, mixed $... ]] ) Returns a string produced according to the formatting string format
51 sscanf mixed sscanf ( string $str , string $format [, mixed &$... ] ) Parses input from a string according to a format
52 str_getcsv $Data = str_getcsv($CsvString, "\n") Parse a CSV string into an array
53 str_ireplace mixed str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) Case-insensitive version of str_replace()
54 str_pad echo str_pad($input, 10) Pad a string to a certain length with another string
55 str_repeat string str_repeat ( string $input , int $multiplier ) Returns input repeated multiplier times
56 str_replace $bodytag = str_replace("%body%", "black", "") Replace all occurrences of the search string with the replacement string
57 str_rot13 string str_rot13 ( string $str ) Perform the rot13 transform on a string
58 str_shuffle string str_shuffle ( string $str ) Randomly shuffles a string
59 str_split array str_split ( string $string [, int $split_length = 1 ] ) Convert a string to an array
60 str_word_count mixed str_word_count ( string $string [, int $format = 0 [, string $charlist ]] ) Return information about words used in a string
61 strcasecmp int strcasecmp ( string $str1 , string $str2 ) Binary safe case-insensitive string comparison
62 strchr $result_string = substr("$string1",0,$position_num) Alias of strstr()
63 strcmp int strcmp ( string $str1 , string $str2 ) Binary safe string comparison
64 strcoll int strcoll ( string $str1 , string $str2 ) Locale based string comparison
65 strcspn $c = strcspn('hello', 'l') Find length of initial segment not matching mask
66 strip_tags string strip_tags ( string $str [, string $allowable_tags ] ) Strip HTML and PHP tags from a string
67 stripcslashes string stripcslashes ( string $str ) Returns a string with backslashes stripped off
68 stripos $pos1 = stripos("apple", "pl") Find the position of the first occurrence of a case-insensitive substring in a string
69 stripslashes string stripslashes ( string $str ) Un-quotes a quoted string
70 stristr echo stristr('[email protected], 'e') Case-insensitive php strstr
71 strlen int strlen ( string $string ) Get string length
72 strnatcasecmp int strnatcasecmp ( string $str1 , string $str2 ) Case insensitive string comparisons using a "natural order" algorithm
73 strnatcmp int strnatcmp ( string $str1 , string $str2 ) String comparisons using a "natural order" algorithm
74 strncasecmp int strncasecmp ( string $str1 , string $str2 , int $len ) Binary safe case-insensitive string comparison of the first n characters
75 strncmp int strncmp ( string $str1 , string $str2 , int $len ) Binary safe string comparison of the first n characters
76 strpbrk string strpbrk ( string $haystack , string $char_list ) Search a string for any of a set of characters
77 strpos int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) Find the position of the first occurrence of a substring in a string
78 strrchr string strrchr ( string $haystack , mixed $needle ) Find the last occurrence of a character in a string
79 strrev string strrev ( string $string ) Reverse a string
80 strripos int strripos ( string $haystack , string $needle [, int $offset = 0 ] ) Find the position of the last occurrence of a case-insensitive substring in a string
81 strrpos int strrpos ( string $haystack , string $needle [, int $offset = 0 ] ) Find the position of the last occurrence of a substring in a string
82 strspn var_dump(strspn("foo", "o")) Finds the length of the initial segment of a string consisting entirely of characters contained within a given mask
83 strstr $domain = strstr('[email protected]', '@'); Find the first occurrence of a string
84 strtok string strtok ( string $token ) Tokenize string
85 strtolower string strtolower ( string $str ) Make a string lowercase
86 strtoupper string strtoupper ( string $string ) Make a string uppercase
87 strtr string strtr ( string $str , string $from , string $to ) or string strtr ( string $str , array $replace_pairs ) Translate characters or replace substrings
88 substr_compare echo substr_compare("abcde", "bc", 1, 2) Binary safe comparison of two strings from an offset, up to length characters
89 substr_count int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] ) Count the number of substring occurrences
90 substr_replace mixed substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ]) Replace text within a portion of a string
91 substr string substr ( string $string , int $start [, int $length ] ) Return part of a string
92 trim string trim ( string $str , $charlist) Strip whitespace (or other characters) from the beginning and end of a string
93 ucfirst string ucfirst ( string $str ) Make a string's first character uppercase
94 ucwords string ucwords ( string $str ) Uppercase the first character of each word in a string
95 vfprintf int vfprintf ( resource $handle , string $format , array $args ) Write a formatted string to a stream
96 vprintf int vprintf (format , array $args ) Output a formatted string
97 vsprintf string vsprintf (format , array $args ) writes a formatted string to a variable.
98 wordwrap wordwrap(string,width,break,cut); Wraps a string to a given number of characters

Related Links

Navigation
Web
SQL
MISC
References