Show Menu
Cheatography

strings Cheat Sheet (DRAFT) by

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_re­place
Replace all occurr­ences of the search string with the replac­ement string
str_ir­eplace
Case-i­nse­nsitive version of str_re­place()
substr­_re­place
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-i­nse­nsitive string comparison
strncmp
Binary safe string comparison of the first n characters
strnca­secmp
Binary safe case-i­nse­nsitive string comparison of the first n characters
substr­_co­mpare
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 inform­ation about characters used in a string
substr­_count
Count the number of substring occurr­ences

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-i­nse­nsitive 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-i­nse­nsitive substring in a string
strpbrk
Search a string for any of a set of characters
strchr
Allias of strstr