PHP - String Functions



PHP String Functions allow you to work with text (referred to as "strings") easier. You can format, search, and modify strings with these functions. When you want to make your application dynamic and interactive, they are really helpful. These functions are the part of the core PHP.

Installation

There is no installation required to use this function.

Runtime Configurations

Special runtime configurations are not needed for PHP string functions. But the php.ini file contains several settings that you can change, like - PHP's memory usage is limited by the Memory Limit. Also, Error Reporting helps in the debugging of your code.

Basic string operations typically work well with the default parameters.

Requirements

To use PHP string functions, you need - PHP Installed and the version should be 4.0 or higher supports most string functions. you need web servers Like Apache or Nginx. And operating systems like Windows, macOS, Linux, etc.

Predefined Constants

PHP has some predefined constants related to strings −

Sr.No Constant & Description
1

CRYPT_STD_DES (int)

Indicates whether standard DES-based hashes are supported in crypt(). Always 1.

2

CRYPT_EXT_DES (int)

Indicates whether extended DES-based hashes are supported in crypt(). Always 1.

3

CRYPT_MD5 (int)

Indicates whether MD5 hashes are supported in crypt(). Always 1.

4

CRYPT_BLOWFISH (int)

Indicates whether Blowfish hashes are supported in crypt(). Always 1.

5

CRYPT_SHA256 (int)

Indicates whether SHA-256 hashes are supported in crypt(). Always 1.

6

CRYPT_SHA512 (int)

Indicates whether SHA-512 hashes are supported in crypt(). Always 1.

7

HTML_SPECIALCHARS (int)

8

HTML_ENTITIES (int)

9

ENT_COMPAT (int)

10

ENT_QUOTES (int)

11

ENT_NOQUOTES (int)

12

ENT_IGNORE (int)

13

ENT_SUBSTITUTE (int)

14

ENT_DISALLOWED (int)

15

ENT_HTML401 (int)

16

ENT_XML1 (int)

17

ENT_XHTML (int)

18

ENT_HTML5 (int)

19

CHAR_MAX (int)

20

LC_CTYPE (int)

Character classification and conversion affected by locale setting.

21

LC_NUMERIC (int)

Decimal separator affected by locale setting.

22

LC_TIME (int)

Date and time formatting affected by locale setting.

23

LC_COLLATE (int)

String comparison affected by locale setting.

24

LC_MONETARY (int)

Monetary formatting affected by locale setting.

25

LC_ALL (int)

Affects all functions that any of the other LC_* constants affect.

26

LC_MESSAGES (int)

System responses affected by locale setting. Available if PHP was compiled with libintl.

27

STR_PAD_LEFT (int)

28

STR_PAD_RIGHT (int)

29

STR_PAD_BOTH (int)

The nl_langinfo() LC_TIME Category Constants

Here is the list of nl_langinfo LC_TIME category constants −

Sr.No Constant & Description
1

ABDAY_1 (int)

Abbreviated name of first day of the week.

2

ABDAY_2 (int)

Abbreviated name of second day of the week.

3

ABDAY_3 (int)

Abbreviated name of third day of the week.

4

ABDAY_4 (int)

Abbreviated name of fourth day of the week.

5

ABDAY_5 (int)

Abbreviated name of fifth day of the week.

6

ABDAY_6 (int)

Abbreviated name of sixth day of the week.

7

ABDAY_7 (int)

Abbreviated name of seventh day of the week.

8

DAY_1 (int)

Name of the first day of the week.

9

DAY_2 (int)

Name of the second day of the week.

10

DAY_3 (int)

Name of the third day of the week.

11

DAY_4 (int)

Name of the fourth day of the week.

12

DAY_5 (int)

Name of the fifth day of the week.

13

DAY_6 (int)

Name of the sixth day of the week.

14

DAY_7 (int)

Name of the seventh day of the week.

The nl_langinfo() LC_NUMERIC Category Constants

Here is the list of constants of this category −

Sr.No Constant & Description
1

DECIMAL_POINT (int)

Decimal point character.

2

RADIXCHAR (int)

Same value as DECIMAL_POINT.

3

THOUSANDS_SEP (int)

Separator character for thousands (groups of three digits).

4

THOUSEP (int)

Same value as THOUSANDS_SEP.

5

GROUPING (int)

List of Functions

PHP − indicates the earliest version of PHP that supports the function.

Sr.No Function & Description PHP
1 addcslashes()

It returns the string with blackslashes

4
2 addslashes()

It returns the string with blackslashes in front of predefined characters

4
3 bin2hex()

It is used to convert primary data to hexadecimal representation

4
4 chop()

It is used to removes whitespace

4
5 chr()

It returns the specific characters

4
6 chunk_split()

It is used to split a string into chunks.

5
7 convert_cyr_string()

It is used to convert from one Cyrillic character set to another

4
8 convert_uudecode()

It is used to decode a encoded string

5
9 count_chars()

It is used to returns the information about character used in a string

4
10 crc32()

It is used to calculates 32-bit CRC

4
11 crypt()

It is used to hashing the string

4
12 echo()

It is give the output as one or more string

4
13 explode()

It is used to split a string by string

4
14 fprintf()

It is used to write a formatted string to a stream

5
15 get_html_translation_table()

It returns the translation table used by htmlspecialchars() and htmlentities()

4
16 hebrev()

It is used to convert logical Hebrew text to visual text

4
17 hebrevc()

It is used to convert logical Hebrew text to visual text with newline conversion

4
18 hex2bin()

It is used to convert a string of hexadecimal to ASCII character

4
19 html_entity_decode()

It is used to convert HTML entities to their application characters

4
20 htmlentities()

It is used to convert all applicable characters to Html entities

5.4
21 html_special_chars_decode()

It is used to convert convert special HTML entities back to characters.

5.1.0
22 htmlspecialchars()

It is used to convert special characters to HTML entities

4
23 implode()

It is used to Join array elements with a string.

5
24 join()

It is alias of implode(), it returns string from the elements of an array

4
25 lcfirst()

It is used to make a string's first character should be lowercase.

5.3.0
26 levenshtein()

It is used calculate Levenshtein distance between two strings

4.0.1
27 localeconv()

It is used to get numeric formatting information

4
28 ltrim()

It used to strip whitespace or other characters from the beginning of a string

4
29 md5_file()

It is used to calculates the md5 hash of a given file

4
30 md5()

It is used to calculates the md5 hash of a string

4
31 metaphone()

It is used to calculates the metaphone key of a string

4
32 money_format()

It is used to formats a number as a currency string

4.3.0
33 nl_langinfo()

It has contained information about language and locale

4.3.0
34 nl2br()

It Inserts HTML line breaks before all newlines in a string

4
35 number_format()

It is used to formats a number with grouped thousands

4
36 ord()

It returns ASCII Value of character

4
37 parse_str()

It is used to parses the string into variables

4
38 print()

It returns output a string

4
39 printf()

It returns output a formatted string

4
40 quoted_printable_decode()

It is used to convert the quoted printable string to 8 bit string

4
41 quoted_printable_encode()

It is used to convert 8 bit string to the quoted printable string

4
42 quotemeta()

It is used to quote meta characters

4
43 rtrim()

It is used to remove the white spaces from end of the string

4
44 setlocale()

It is used to set locale information

4
45 sha1_file()

It is used to calculate the sha1 hash of a file

4
46 sha1()

It is used to calculate the sha1 hash of a string

4
47 similar_text()

It is used to calculate the similarity between two strings

4
48 soundex()

It is used to calculate the soundex key of string

4
49 sprintf()

It is used to a formatted string

4
50 sscanf()

It is used to parse input from a string

4.0.1
51 str_contains()

It is used to check if a string contains a given substring

8
52 str_decrement()

It is used to decrement an alphanumeric string

8.3.0
53 str_ends_with()

It is used to check if a string ends with a substring

8
54 str_getcsv()

It is used to parse parse a CSV string into array

4
55 str_increment()

It is used to increment an alphanumeric string

8.3.0
56 str_ireplace()

It is used to replace the characters with some other characters

5
57 str_pad()

It is used to pads a string to a new length.

4.0.1
58 str_repeat()

It is used to repeat a string

4
59 str_replace()

It is used to replace the string with another string

4
60 str_rot13()

It is used to perform the rot13 transform on a string

4
61 str_shuffle()

It is used to randomly shuffles a string

4.3.0
62 str_split()

It is used to convert a string to an array

5
63 str_starts_with()

It is used to check if a string starts with a substring

8
64 str_word_count()

It returns information about words used in a string

5
65 strcasecmp

It is used to compare two strings

4
66 strchr

It is used to searches for the first occurrence of a string inside another

4
67 strcmp

It is used to compare two strings

4
68 strcoll

It is used to compare two strings based on locale

4.0.5
69 strcspn

It returns number of characters find in a string before any part of the specified characters are found.

4
70 strip_tags()

It is used to string HTML and PHP tags from a string.

4
71 stripcslashes()

It is used to removes backslashes

4
72 stripos()

It is used to find the position of first occurrence of a string inside the another string

4
73 stripslashes()

It is used to un-quoted a quoted string

4
74 stristr()

It is used searches for the first occurrence of a string inside another string.

4
75 strlen()

It is used get string length.

4
76 strnatcasecmp()

It is used compare two strings with a natural algorithm.

4
77 strnatcmp()

It is used compare two strings with a natural order algorithm.

4
78 strncasecmp()

It is used compare two strings.

4
79 strncmp()

It is used compare first n character.

4
80 strpbrk()

It is used search's a string for a specific character.

5
81 strpos()

It is used to find the position of first occurrence of a string inside another string.

4
82 strrchr()

It is used to find the last occurrence of a character in a string.

4
83 strrev()

It is used to reverse a string.

4
84 strripos()

It is used find the position of the last occurrence of a string inside the another string

5
85 strspn()

It returns number of characters found in the string from the charlist parameter.

4
86 strstr()

It is used to find the first occurrence of a string

4
87 strtok()

It is a tokenize string

4
88 strtolower()

It used to make a string lower case

4
89 strtoupper()

It used to make a string upper case

4
90 strtr()

It used to translates character or replace substring

4
91 substr_compare()

It used to compare two string format with a specific start position

4
92 substr_count()

It used to count the number of sub strings

4
93 substr_replace()

It used to replace the part of string with another string

4
94 substr()

It used to return a part of a string

4
95 trim()

It used to remove the whitespaces and other characters

4
96 ucfirst

It used to convert the first character of a string to upper case

4
97 ucwords()

It used to convert the first character of a string to upper case in each string

4
98 vfprintf()

It used to convert formatted string to specific output

5
99 vprintf()

It used to convert string to formatted string

4.1
100 vsprintf()

It returns the formatted string

4.1
101 wordwrap()

It used to convert the long words to be broken and its arrange to the next line

4.0.2
php_function_reference.htm
Advertisements