PHP String Function

Post on 04-Mar-2016

20 views 0 download

description

PHP string function helps us to manipulate string in various ways. There are various types of string function available. Here we discuss some important functions and its use with examples.

transcript

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 1/11

PHP String Function

ADMEC MULTIMEDIA

Leader in Animation & Digital MediaEducation

ISO 9001:200 !E"#IFIED $ ADO%E #eting !enter'''(admecindia(co(in

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 2/11

PHP string function helps us to manipulate string in various ways.

There are various types of string function available.

Here we discuss some important functions and its use with examples.

1(ec)o2(trtolo'er * +,(trtou--er * +.(lc/rt*+

(uc/rt*+(uc'ord*+(u3tr4re-lace * +

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 3/11

1. echo: It is used to print one or more string .Echo

function is faster than print print function.

Example:<!doctype <!DOCTYPE html><html><head>

<title>string function</title></head><body>

<phpecho "tring #unction>

</body></html>

 Output:String Function

//echo is not actually function so we are notrequired to use parentheses with it.

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 4/11

2. strtolower: It converts a string to lower case letter.

Example:

<!doctype <!DOCTYPE html><html><head>

<title>string function</title></head>

<body><phpecho strtolo%er&"T'()* #unction+ ,>

</body></html> 

Output:string function

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 5/11

3. strtoupper ( ): It converts a string to upper case

letter.

Example:

<!doctype <!DOCTYPE html><html><head>

<title>string function</title></head><body>

<phpecho strtoupper&"tring #unction+ ,>

</body>

</html> 

Output:STI!" #$!%TIO!

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 6/11

4. lcfirst( ): It converts the first character of a string to

lower.

Example:

<!doctype <!DOCTYPE html><html><head>

<title>string function</title>

</head><body>

<phpecho lc-rst&"tring #unction+ ,>

</body>

</html> 

Output:string #unction

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 7/11

5. ucfirst( ): It converts the first character of a string

to upper case.

Example:

 <!doctype <!DOCTYPE html><html><head>

<title>string function</title></head><body>

<phpecho uc-rst&string function+ ,>

</body>

</html> 

Output:String function

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 8/11

6. ucwords( ): It converts the first character of every

 word to upper case.

Example:

 <!doctype <!DOCTYPE html><html><head>

<title>string function</title></head><body>

<phpecho uc%ords&string function+ ,>

</body>

</html> 

Output:String #unction

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 9/11

7. substr_replace( ): It replaces a part of a string

 with another string.

The syntax is:Substr&replace 'string( replacement( start ( length)

There are various way to replace string. Here theexamples are *

Example:<!doctype <!DOCTYPE html><html><head>

<title>string function</title></head><body>

<phpecho substr.replace&hello %orldnandon0+,>

</body></html> 

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 10/11

Output:hello nandon

++here it replace world to nandon . !umber , means thereplacement starts from , position of the string.-xample :<!doctype <!DOCTYPE html><html><head>

<title>string function</title></head><body>

<phpecho substr.replace&hello %orld nandon12+,>

</body>

</html>Output:  hello nandon++here in this example we use '/) negative sign so it willcount the word from the right hand side and replace.

7/21/2019 PHP String Function

http://slidepdf.com/reader/full/php-string-function-56d8e32e6ef23 11/11

Contact for PHP Training:ADMEC MULTIMEDIA INSTITUTE

C-7/114, IInd !oor, S"ctor- 7, #o$ini, D"!$i- %&

Land'ar(:  Near Rohini East Metro Station

H"!)!in" 1: +91 9811 818 122

H"!)!in" *:  +91 9911 782 350

  ADMEC MULTIMEDIA  L"ad"r in Ani'ation + Digita! M"dia Edcation

  IS .1:*% CE#TIIED 0 ADE T"2ting C"nt"r

  ADMEC MULTIMEDIA INSTITUTE

   For More information you can visit :

$tt)://333ad'"cindiacoin