Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

PHP String Functions


PHP provides various string functions to access and manipulate strings. A list of important PHP string functions are given below.

1) PHP strtolower() function

The strtolower() function returns string in lowercase letter.

Syntax

  1. string strtolower ( string $string )

Example

  1. <?php
  2. $str=“My name is KHAN”;
  3. $str=strtolower($str);
  4. echo $str;
  5. ?>

Output:

my name is khan

2) PHP strtoupper() function

The strtoupper() function returns string in uppercase letter.

Syntax

  1. string strtoupper ( string $string )

Example

  1. <?php
  2. $str=“My name is KHAN”;
  3. $str=strtoupper($str);
  4. echo $str;
  5. ?>

Output:

MY NAME IS KHAN

3) PHP ucfirst() function

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

Syntax

  1. string ucfirst ( string $str )

Example

  1. <?php
  2. $str=“my name is KHAN”;
  3. $str=ucfirst($str);
  4. echo $str;
  5. ?>

Output:

My name is KHAN

4) PHP lcfirst() function

The lcfirst() function returns string converting first character into lowercase. It doesn’t change the case of other characters.

Syntax

  1. string lcfirst ( string $str )

Example

  1. <?php
  2. $str=“MY name IS KHAN”;
  3. $str=lcfirst($str);
  4. echo $str;
  5. ?>

Output:

mY name IS KHAN

5) PHP ucwords() function

The ucwords() function returns string converting first character of each word into uppercase.

Syntax

  1. string ucwords ( string $str )

Example

  1. <?php
  2. $str=“my name is Sonoo jaiswal”;
  3. $str=ucwords($str);
  4. echo $str;
  5. ?>

Output:

My Name Is Sonoo Jaiswal

6) PHP strrev() function

The strrev() function returns reversed string.

Syntax

  1. string strrev ( string $string )

Example

  1. <?php
  2. $str=“my name is Sonoo jaiswal”;
  3. $str=strrev($str);
  4. echo $str;
  5. ?>

Output:

lawsiaj oonoS si eman ym

7) PHP strlen() function

The strlen() function returns length of the string.

Syntax

  1. int strlen ( string $string )

Example

  1. <?php
  2. $str=“my name is Sonoo jaiswal”;
  3. $str=strlen($str);
  4. echo $str;
  5. ?>

Output:

24

Comments

comments