welcome to tutorialfamily

php string

Php string – It is sequence of characters.

“Hello, how are you” is a string.


php string function

Data type are give below.

  • strlen() :Return the Length of a String
  • str_word_count() :Words Count in a String
  • strpos() :Search Text Within a String
  • strrev() :Reverse a String
  • str_replace() :Replace Text Within a String

php strlen() function

This function return the length of the string

for example “Hello”, Hello string length is 5 (count the letter).


strlen() function



<!DOCTYPE html>
<html>
<head>
	<title>strlen()</title>
</head>
<body>
<?php
	echo strlen("Welcome to tutorialfamily.com"); 
?>
</body>
</html>

output

str_word_count() function

It is use for count the word of given string.

For example: “Welcome to my website”. output: 4 (four word in given sentence)


str_word_count() function



<!DOCTYPE html>
<html>
<head>
	<title>string word count</title>
</head>
<body>
<?php
	echo str_word_count("Hello welcome to tutorialfamily.com"); 
?>
</body>
</html>

output

strpos() function

Search the text within the string.

It function search the repeat text and give the position of the text. If match not found, it will return false.


strpos() function



<!DOCTYPE html>
<html>
<head>
	<title>strpos() function</title>
</head>
<body>
<?php
	echo strpos("Welcome to tutorialfamily", "tutorialfamily"); 
?>
</body>
</html>

output

strrev() function

It is use for reverse the string.


strrev() function



<!DOCTYPE html>
<html>
<head>
	<title>strrev() function</title>
</head>
<body>
<?php
	echo strrev("Welcome to tutorialfamily.com"); 
?>
</body>
</html>

output

str_replace() function

It is use for replace the text with some other text in given string.


str_replace() function



<!DOCTYPE html>
<html>
<head>
	<title>str_replace() function</title>
</head>
<body>
<?php
	echo str_replace("Apple", "Banana", "My favourite fruite is Apple"); // outputs My favourite fruite is Banana
?>
</body>
</html>

output

Our Content