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
- Read also: How to pass a variable from the command line using PHP?
- How to Get All Google play store apps List using PHP Scraper?
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 ЁЯШК
Recommended post
- How to Get All Google play store apps List using PHP Scraper?
- How to pass a variable from the command line using PHP?
- How to Submit Registration and Login Form in PHP?
- Introduction PHP
- how to declare variables in PHP?
- What things you need to install PHP?
- How to get meta tags in 2 easy way in PHP
- How to Encode and Decode Strings with Base64 in JavaScript examples
- How to Reset DropDownList Selection Using jQuery?
- Create dynamic drop-down list option with JavaScript and jQuery
- Onclick show and hide div using JQuery with examples
Thank you for sharing this informative post. Looking forward to read more.
ReplyDeleteBest PHP Development Services
Post a Comment
Please do not enter any spam link in the comment section.