PHP String Functions

PHP is equally powerful than any other server side scripting languages in handling strings. We will experiment with some of the string functions of PHP with some examples. There are powerful functions like regular expressions to manage complex string handling requirements. Here are some of them.
Functions Description
fgetcsv()Getting data from CSV file
fputcsv()Writing data to a CSV file
htmlspecialchars()Converting HTML chars
lcfirst()First char to lower case
preg_replace()regular expression string replacement
md5()String encryption
nl2br()Converting Line breaks to HTML <BR> tags
password_hash()One way password hash
password_verify()Matching string with password hash
strip_tags()Removing HTML tags from string & keeping text part
str_replace()Case sensitive string replacement
str_ireplace()Case in-sensitive string replacement
substr_count()Counting presence of sub-string inside a main string
str_repeat()Repeating string
str_word_count()Counting Words in a string
random_bytes()cryptographically secure random bytes ( PHP 7 )
strrev()Reversing a string
strlen()Length of a string
strstr()Searching string with needle ( Case sensitive )
stristr()Searching string with needle ( Case in-sensitive )
split()Breaking string using delimiter
explode()Breaking string using delimiter
substr()Part of the string with length and position
strtolower()Changing all upper case char to lower case
strtoupper()Changing all lower case char to Upper case
strcasecmp()case in-sensitive string comparison
strcmp()case sensitive string comparison
str_pad()Padding string from left , right or both sides
trim()Removing char or blank space from left , right and both sides of a string
ucwords()Change to upper case for each first char of all the words of a string
ucfirst()Change to upper case for first char of a string
wordwrap()Wrapping the string after a width
  • strpos() case-sensitive search returns position of first occurrence
  • stripos() case-insensitive search returns position of first occurrence
  • strrpos() case-sensitive search returns position of last occurrence
  • strripos() case-insensitive search returns position of last occurrence


Check the input string is Palindrome or not

ctype_lower() & ctype_upper()

checking presence of lower or upper case letter only.

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
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    PHP String Functions


    Its good information

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2023 All rights reserved worldwide Privacy Policy Disclaimer