String function in php

php string functions

 

Strlen()

To get length of string.

Example
 

 

Output   : 7
 

Note   :-    ord() is used for getting ascii value.

 

Strtoupper()

Converts all character of a string  into upper case .

Example

 

Output; HELLO

 

Strtolower():

Converts characters of a string into lower case.

Ucfirst():

Converts first characters of a string into upper case.

 

Example :

 

 

Output  Codelack

 

Ucwords()

Converts  first character of all words into upper case.

Example :

 

 

Output     Codelack In Php

 

Nl2br()

To break new lines of  string.

 

 

Output  :-

codelack New  tutarial Site

 

Str_word_count()

To get total number of words of a string.

We can pass node value. If node value is 0, it rerurns total no of words.

If node value is 2, it returns each word as array elements keys  the index numbers of words.

Example:

 

 

Output:

Array (

[0]=>welcome

[8]=>codelack

[14]=> tutorial

)

Strip_tags()

To strip HTML of a string.

Example

 

 

Output: –

Codelack

Htmlspecialchars()

To stop execution of html tags.

Example

 

 

Output:

<b><i>codelack</i></b>

 

Addslashes():

To add escape slashes (backslashes /) in front of single and double quotation.

 

Atripslashes()

To remove the slashes , which we added with add slashes function (addslashes()).

Example

 

Output:-

Wel\come

Welc’ome