PHP String Functions – Strrev, strlen, implode, trim

PHP string functions tutorial, the string is a collection of characters. Through this tutorial, you will learn most useful PHP string functions. If you work with php or any php framework at that time you need to require basic PHP functions. This PHP string function is very easy and helpful.

PHP String Functions – Strrev, strlen, implode, trim

Top 10+ String Functions in PHP

PHP has several built-in string functions. top 10+ string function in PHP :

  • 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 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 the 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.