PHP String Functions

PHP Provides wide range of functions to perform operations on string.

String Length Function Example

String Length Function will return the total characters in string.

	<?php
	//String Length
	echo strlen("Hello World"); //Output 11
	?>

Reverse String Function Example

	<?php
	//Reverse String
	echo strrev("elppA"); //Output Apple
	?>

String Search Example

Want to find any specific word from sentence. it will return the starting point of word.

	<?php
	//Search For a Specific Text Within a String
	echo strpos("I Love My Country","My"); //Output 7
	?>

Replace Text Function Example

Many time we require to replace the word in variable at runtime for this php provide str_replace() function.

	<?php
	//Replace Text Within a String
	echo str_replace("Friend","Brother","Hello Friend");//Output Hello Brother
	?>

Repeat String Function Example

	<?php
	
	//Repeat the string
	echo str_repeat("ha",4);//output hahahaha
	
	?>

Uppercase Function Example

Converts the string characters to upper case.

	<?php
	//String to UpperCase
	echo strtoupper("Pakistan"); //Output PAKISTAN
	?>

Lowercase Function Example

Converts the string characters to lower case.

	<?php
	//string to LowerCase
	echo strtolower("pHp"); //Output php
	?>