PHP String Functions PHP
- PHP Tutorial
- What is PHP
- Install PHP
- PHP Example
- PHP Echo
- PHP Print
- PHP Variables
- PHP $ and $$ Variables
- PHP Constants
- Magic Constants
- PHP Data Types
- PHP Operators
- PHP Comments
- PHP Boolean
- PHP is_bool() function
- PHP Integer
- PHP is_int() function
- PHP Float
- PHP is_float Function
- PHP Compound Types
- PHP Special Types
- PHP is_null() function
- PHP If Else
- PHP Switch
- PHP For Loop
- PHP While Loop
- PHP do while loop
- PHP Break
- PHP Functions
- PHP Parameterized Function
- PHP Call By Value
- PHP Call By Reference
- PHP Default Argument Values Function
- PHP Variable Length Argument Function
- PHP Recursive Function
- PHP Arrays
- PHP Indexed Array
- PHP Associative Array
- PHP Multidimensional Array
- PHP Array Functions
- PHP String
- PHP String Functions
- PHP Math functions
- PHP Form Handling | GET and POST method
- PHP Include File
- PHP Cookie
- PHP Session
- PHP File Handling
- PHP Open File
- PHP Read File
- PHP Write File
- PHP Append to File
- PHP Delete File
- PHP File Upload
- PHP Download File
- PHP Mail
- PHP MySQL Connect
- PHP MySQL Create Database
- PHP MySQL Create Table Example
- PHP MySQL Insert Record
- PHP Prepared Statements
- PHP MySQL Update Record
- PHP MySQL Delete Record
- PHP MySQL Select
- PHP MySQL Order By
- PHP Limit Data MySql
- PHP JSON
- PHP XML Parsers
- PHP SimpleXML Parser
- PHP SimpleXML - Get Node/Attribute Values
- PHP XML Expat Parser
- PHP XML DOM Parser
- PHP - AJAX intro
- MySQL CREATE VIEW
PHP String Functions
PHP String Functions
PHP provides various string functions to access and manipulate strings. A list of important PHP string functions are given below.
PHP STRING FUNTIONS
addcslashes() | It is used to return a string with backslashes. |
addslashes() | It is used to return a string with backslashes. |
bin2hex() | It is used to converts a string of ASCII characters to hexadecimal values. |
chop() | It removes whitespace or other characters from the right end of a string |
chr() | It is used to return a character from a specified ASCII value. |
chunk_split() | It is used to split a string into a series of smaller parts. |
convert_cyr_string() | It is used to convert a string from one Cyrillic character-set to another. |
convert_uudecode() | It is used to decode a uuencoded string. |
convert_uuencode() | It is used to encode a string using the uuencode algorithm. |
count_chars() | It is used to return information about characters used in a string. |
crc32() | It is used to calculate a 32-bit CRC for a string. |
crypt() | It is used to create hashing string One-way. |
echo() | It is used for output one or more strings. |
explode() | It is used to break a string into an array. |
hebrev() | It is used to convert Hebrew text to visual text. |
hebrevc() | It is used to convert Hebrew text to visual text and new lines (\n) into <br>. |
hex2bin() | It is used to convert string of hexadecimal values to ASCII characters. |
print() | It is used for output one or more strings. |
fprint() | It is used to write a formatted string to a stream. |
nl2br() | It is used to insert HTML line breaks in front of each newline in a string. |
number_format() | It is used to format a number with grouped thousands. |
htmlentities() | It is used to convert character to HTML entities. |
html_entity_decode() | It is used to convert HTML entities to characters. |
ord() | It is used to return ASCII value of the first character of a string. |
parse_str() | It is used to parse a query string into variables. |
Implode() | It is used to return a string from the elements of an array. |
Lcfirst() | It is used to convert the first character of a string to lowercase. |
Join() | It is the Alias of implode() function. |
Levenshtein() | It is used to return the Levenshtein distance between two strings. |
trim() | It is used to remove whitespace. |
ltrim() | It is used to remove whitespace from the left side of a string. |
rtrim() | It is used to remove whitespace from the right side of a string. |
md5() | It is used to calculate the MD5 hash of a string. |
md5_files() | It is used to calculate MD5 hash of a file. |
metaphone() | It is used to calculate the metaphone key of a string. |
Soundex() | It is is used to calculate the soundex key of a string. |
setlocale() | It is used to set locale information. |
money_format() | It is used to return a string formatted as a currency string. |
printf() | It is used to show output as a formatted string. |
sha1() | It is used to return the SHA-1 hash of a string. |
sscanf() | It is used to parse input from a string according to a format. |
str_getcsv() | It is used to parse a CSV string into an array. |
sha1_file() | It is used to return the SHA-1 hash of a file. |
similar_text() | It is used to compare the similarity between two strings. |
str_pad() | It is used to pad a string to a new length. |
str_ireplace() | It is used to replace some characters in a string (case-insensitive). |
str_repeat() | It is used to repeat a string a specified number of times. |
str_rot13() | It is used to perform the ROT13 encoding on a string. |
str_shuffle() | It is used to randomly shuffle all characters in a string. |
str_split() | It is used to split a string into an array. |
str_word_count() | It is used to count the number of words in a string. |
strcasecmp() | It is used to compare two strings. |
strchr() | It is used to find the first occurrence of a string inside another string. |
stscroll() | It is locale based string comparison. |
strcmp() | It is binary safe string comparison. |
strcspn() | It is used to reverses a string. |
strip_tags() | It is used to strip HTML and PHP tags from a string. |
stripcslashes() | It is used to unquote a string quoted with addcslashes(). |
stripos() | It is used to return the position of the first occurrence of a string inside another string. |
strlen() | It is used to return the length of a string. |
strnatcasecmp() | It is used to compare two strings using a "natural order" algorithm. |
strnatcmp() | It is used to compare two strings using a "natural order" algorithm. |
strncmp() | It is used to compare of the first n characters. |
strpbrk() | It is used to search a string for any of a set of characters. |
strpos() | It is used to return the position of the first occurrence of a string inside another string. |
strrchr() | It is used to find the last occurrence of a string inside another string. |
strrev() | It is used to reverse a string. |
1) PHP strtolower() function
The strtolower() function returns string in lowercase letter.
Syntax
- string strtolower ( string $string )
Example
- <?php
- $str="My name is KHAN";
- $str=strtolower($str);
- echo $str;
- ?>
Output:
2) PHP strtoupper() function
The strtoupper() function returns string in uppercase letter.
Syntax
- string strtoupper ( string $string )
Example
- <?php
- $str="My name is KHAN";
- $str=strtoupper($str);
- echo $str;
- ?>
Output:
3) PHP ucfirst() function
The ucfirst() function returns string converting first character into uppercase. It doesn't change the case of other characters.
Syntax
- string ucfirst ( string $str )
Example
- <?php
- $str="my name is KHAN";
- $str=ucfirst($str);
- echo $str;
- ?>
Output:
4) PHP lcfirst() function
The lcfirst() function returns string converting first character into lowercase. It doesn't change the case of other characters.
Syntax
- string lcfirst ( string $str )
Example
- <?php
- $str="MY name IS KHAN";
- $str=lcfirst($str);
- echo $str;
- ?>
Output:
5) PHP ucwords() function
The ucwords() function returns string converting first character of each word into uppercase.
Syntax
- string ucwords ( string $str )
Example
- <?php
- $str="my name is Sonoo jaiswal";
- $str=ucwords($str);
- echo $str;
- ?>
Output:
6) PHP strrev() function
The strrev() function returns reversed string.
Syntax
- string strrev ( string $string )
Example
- <?php
- $str="my name is Sonoo jaiswal";
- $str=strrev($str);
- echo $str;
- ?>
Output:
7) PHP strlen() function
The strlen() function returns length of the string.
Syntax
- int strlen ( string $string )
Example
- <?php
- $str="my name is Sonoo jaiswal";
- $str=strlen($str);
- echo $str;
- ?>
Output: