PHP String Functions
PHP
PHP provides a rich set of built-in string functions that allow developers to manipulate and process text efficiently. These functions enable operations such as searching, replacing, formatting, splitting, and comparing strings, among other tasks. Below is a categorized list of PHP string functions based on their functionality.
String Manipulation and Formatting
Functions Description
addslashes() Escape Special Characters
chop() Remove blank space at the end of the string
chunk_split() Break string after a position
str_split() Split a string with fixed intervals (without using any delimiter)
str_pad() Padding string from left, right, or both sides
strrev() Reversing a string
stripslashes() to Remove Backslashes
sprintf() Formatting strings for numbers, and other data types
nl2br() Converting line breaks to HTML <BR> tags
str_shuffle() Shuffle a string
str_repeat() Repeat a string multiple times
trim() Removing char or blank space from left, right, and both sides of a string
wordwrap() Wrapping the string after a width
String Search and Substring Extraction
Functions Description
strpos() Case-sensitive search returns position of the first occurrence
stripos() Case-insensitive search returns position of the first occurrence
strrpos() Case-sensitive search returns position of the last occurrence
strripos() Case-insensitive search returns position of the last occurrence
strchr() Return the substring from the matching point
strrchr() Find the last occurrence of a character and return the substring
strstr() Search for string with needle (case-sensitive)
stristr() Search for string with needle (case-insensitive)
substr() Extract part of the string based on position and length
substr_count() Count the number of times a substring occurs in a string
String Replacement
String Case Conversion
Functions Description
strtolower() Convert all characters to lowercase
strtoupper() Convert all characters to uppercase
lcfirst() Convert the first character to lowercase
ucfirst() Convert the first character to uppercase
ucwords() Convert the first character of every word to uppercase
String Comparison
Functions Description
strcasecmp() Case-insensitive string comparison
strcmp() Case-sensitive string comparison
strcoll() locale-based string comparison
similar_text() Comparing strings to get the percentage of similarity
String Operations with Arrays and Delimiters
Functions Description
explode() Break a string into an array using a delimiter
implode() Join array elements into a string
split() Break a string using a delimiter
ASCII and Character Functions
Functions Description
chr() Return a character from an ASCII value
ord() Return the ASCII value of a character
count_chars() Return information about the characters used in a string
Encryption and Hashing
HTML and Special Characters
CSV Handling
Miscellaneous Functions
Scripts using String functions in PHP
Palindrome →
Check the input string is Palindrome or not
ctype_lower() & ctype_upper()→
checking presence of lower or upper case letter only.
Checking String→
Checking string for presence of Upper case or lower case letter or special characters or space.
Random string→
We can generate random string by using rand function
Removing chars from end→
Remove chars from end of the string by using length and sub string functions
Adding strings→
Add two or more strings including date.
Collecting part of string→
Extracting string part using two landmark points
Email part →
Getting the domain and Userid part from an email address
Questions
What is the purpose of the strlen()
function in PHP? How do you use it?
How can you convert a string to all uppercase letters using a PHP string function?
Explain the difference between strpos()
and stripos()
functions in PHP.
How can you extract a substring from a given string using the substr()
function in PHP?
What is the purpose of the str_replace()
function in PHP? Provide an example of how you would use it.
How do you check if a string starts with a specific substring in PHP? Which string function would you use?
How can you concatenate two strings in PHP? Is there a specific function for that?
What is the purpose of the trim()
function in PHP? How does it differ from ltrim()
and rtrim()
?
How can you split a string into an array of substrings based on a specific delimiter using a PHP string function?
Explain the purpose and usage of the str_shuffle()
function in PHP.
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com
satish 13-03-2013
Its good information