String Functions in PHP

Hi, friends Today we will learn how many String Function in PHP and their examples.
So let's start.

There are some String functions which is mostly used in PHP.


1- strlen()

This function return length of the string.


     Example

   <?php

     $x = "Hello short tutorials";


     echo strlen($x); // Output 21


   ?>

 

Note* it counts of space also


2- str_word_count()

This function return counts the number of words.

Example


<?php $x = "Hello short tutorials"; echo str_word_count($x); // output 3 ?>

 

3- strrev()

This function return reverse of a string.

Example


<?php $x = "Hello short tutorials"; echo strrev($x); // Output slairotut trohs olleH ?>



Read also: How to Reset DropDownList Selection Using jQuery?

4- strpos()

This function is used to search a text in String, if search data exists in the string it returns the character of position else it does not exist in the string it returns false.

Example


<?php // when search data is exists in data . $data= "Hello short tutorials"; $search_text = "tutorials"; echo strpost($data , $search_text ); // Output 12 // when search text does not exists in data . $data= "Hello short tutorials"; $search_text = "tutorialssss"; echo strpost($data , $search_text ); // Output False ?>


5- str_replace()

This function replaces the character to another character in String.

Example


<?php $data = "Hello Full tutorials"; echo str_replace("Full","Short",$data); // Output Hello Short tutorials ?>

 

Yeah! You have learned ЁЯШК

I hope you understood this and like this article. if you like it so, please give feedback in the comment section.

If any mistakes I made here, so please let me know and improve me.
If you have any query, feel free to ask me ЁЯШК


1 Comments

Please do not enter any spam link in the comment section.

  1. Thank you for sharing this informative post. Looking forward to read more.
    Best PHP Development Services

    ReplyDelete

Post a Comment

Please do not enter any spam link in the comment section.

Previous Post Next Post