Cheatography
https://cheatography.com
Most usefull string functions in PHP
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Replacing
str_replace |
Replace all occurrences of the search string with the replacement string |
str_ireplace |
Case-insensitive version of str_replace() |
substr_replace |
Replace text within a portion of a string |
Matching
substr |
Return part of a string |
Comparing
strcmp |
Binary safe string comparison |
strcasecmp |
Binary safe case-insensitive string comparison |
strncmp |
Binary safe string comparison of the first n characters |
strncasecmp |
Binary safe case-insensitive string comparison of the first n characters |
substr_compare |
Binary safe comparison of two strings from an offset, up to length characters |
Formating
number_format |
Format a number with grouped thousands |
printf |
Output a formatted string |
sprintf |
Return a formatted string |
fprintf |
Write a formatted string to a stream |
vprintf |
Returns the length of the outputted string. |
vsprintf |
Return a formatted string |
vfprintf |
Write a formatted string to a stream |
sscanf |
Parses input from a string according to a format |
fscanf |
Parses input from a file according to a format |
|
|
Converting
chr |
Generate a single-byte string from a number |
ord |
Convert the first byte of a string to a value between 0 and 255 |
Useful functions
implode |
Join array elements with a string |
strlen |
Get string length |
count_chars |
Return information about characters used in a string |
substr_count |
Count the number of substring occurrences |
Spliting strings
explode |
Split a string by a string |
str_split |
Convert a string to an array |
preg_split |
Split string by a regular expression |
|
|
Searching
strstr |
Find the first occurrence of a string |
stristr |
Find the first occurrence of a string |
strpos |
Find the position of the first occurrence of a substring in a string |
stripos |
Find the position of the first occurrence of a case-insensitive substring in a string |
strrpos |
Find the position of the last occurrence of a substring in a string |
strripos |
Find the position of the last occurrence of a case-insensitive substring in a string |
strpbrk |
Search a string for any of a set of characters |
strchr |
Allias of strstr |
|