String Functions in PHP

Advertisements

String in PHP Upload File in PHP

String Functions in PHP

PHP have lots of predefined function which is used to perform operation with string some functions are strlen(), strrev(), strpos() etc.

string function in php

PHP strlen() function

strlen() function returns the length of a string. In below example strlen() function is used to return length of "Hello world!"

strlen() example in php

<?php

echo strlen("Hello world!");

?>

Output

12

PHP str_word_count() function

str_word_count() function is used to count numbers of words in given string.

str_word_count() example in php

<?php

echo str_word_count("Hello world!");

?>

Output

2

PHP strrev() function

strrev() function is used to revers any string.

strrev() example in php

<?php

echo strrev("Hello world!");

?>

Output

!dlrow olleH

PHP strpos() function

strpos() function is used to search specific position of any words in given string.

strpos() example in php

<?php

echo strpos("Hello world!", "world");

?>

Output

6

PHP str_replace() function

str_replace function is used to replaces some characters with some other characters in a string. In below example we replace world with Faiz.

str_replace() example in php

<?php

echo str_replace("world", "Faiz", "Hello world!");

?>

PHP strtolower() function

strtolower() function is used to convert uppercase latter into lowercase latter.

strtolower() example in php

<?php

$str="Hello friends i am HITESH";  
$str=strtolower($str);  
echo $str;  

?>

Output

hello friends i am hitesh

PHP strtoupper() function

PHP strtoupper() function is used to convert lowercase latter into uppercase latter.

strtoupper() example in php

<?php

$str="Hello friends i AM Hitesh";  
$str=strtoupper($str);  
echo $str;  

?>

Output

HELLO FRIENDS I AM HITESH

Output

Hello Faiz!

PHP ucwords() function

ucwords() function is used to convert first latter of every word into upper case.

ucwords() example in php

<?php

$str="hello friends i am hitesh";  
$str=ucwords($str);  
echo $str;  

?>

Output

Hello Friends I Am Hitesh

PHP ucfirst() function

ucfirst() function returns string converting first character into uppercase. It doesn't change the case of other characters.

ucfirst() example in php

<?php

Hello friends I am HITESH  

?>

Output

Hello friends I am HITESH

PHP lcfirst() function

PHP lcfirst() function is used to convert first character into lowercase. It doesn't change the case of other characters.

lcfirst() example in php

<?php

hello friends I am HITESH  

?>

Output

hello friends I am HITESH

String in PHP Upload File in PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements