Top 13 PHP String Functions

In this php string tutorial, string is collection of charactor. we learn about basic most useful php string functions. We will develop any website using php that time we need to require basic php functions.
This php string functions is very easy and helpful.

PHP String Functions :

PHP has many inbuild string functions. some of the common useful fuctions here :

Trim funcition
Ucfirst function
Ucwords function
Strlen function
Strtolower function
Strtoupper function
Lcfirst function
Str Replace function
Str Word Count function
Strrev function
Strpos function
Substr function
Implode function

PHP 7.3.0 improvements and new features :

Flexible Heredoc and Nowdoc Syntax
PCRE2 Migration
Multiple MBString Improvements
LDAP Controls Support
Improved FPM Logging
Windows File Deletion Improvements
Several Deprecations

Let’s start

PHP Trim Function

Trim function is used to removing whitespace both side of sting.

<?php
$str = " Developers! ";
echo trim($str);
?>

PHP Ucfirst Function

Ucfirst string function is used to change to sting first word to uppercase.

<?php
echo ucfirst("hello world!");
?>
//Output
Hello world!

PHP Ucwords Function

This is used to change string each word first charactor to uppercase.

<?php
echo ucwords("hello developers");
?>
//Output
Hello Developers

PHP Strlen Function

Strlen function is used to count length of string.

<?php
echo strlen("developer");
?>
//Output
9

PHP Strtolower Function

Strtolower function is used to change lowercase of each charactor (whole string) of sting.

<?php
echo strtolower("DEVELOPER");
?>
//Output
developer

PHP Strtoupper Function

This function is used to convert uppercase of each charactor ( whole string ) of string.

<?php
echo strtoupper("testing");
?>
//Output
TESTING

PHP Lcfirst Function

This is used to make the first charactor of string to lowercase.

<?php
echo lcfirst("FINAL");
?>
//output
fINAL

PHP Str Replace Function

str_replace function is used to replace the value

<?php
echo str_replace("program","developer","Hello program!");
?>
// output
Hello developer

PHP Str Word Count Function

Str to word function is used to count the number of words in string.

<?php
echo str_word_count("Hello first my name is developer");
?>
// output
6

PHP Strrev Function

Strrev function is used to reversing the string. Use it for reversed to sting.

<?php
echo strrev("Hello");
?>
// output
olleh

PHP Strpos Function

Strpos function is used to find the text in string . If it find the text in string return true or false.

<?php
echo strpos("Welcome to india","india");
?>
// output
11

PHP Substr Function

Substr function is used to show(display) exact words in string.

<?php
echo substr("Hello my name is developer",0,5);
?>
//Output
Hello

PHP  Implode() Function

This function is change array to string :

<?php
$arr = array('Hello','Developers!');
echo implode(" ",$arr);
?>
//Output
Hello Developers

In this php string functions tutorial, we have learned the common useful PHP string functions.

If you have any questions or thoughts to share, use the comment form below to reach us.

Spread the love

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *