String Functions in PHP

Google Advertisements

Prev Tutorial Next Tutorial

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

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs