elibraryportal Logo

String in PHP

string is a sequence of characters enclosed in double quotation mark or single quotation mark like . "Hello world!".

1) Calculating the Length of a String in PHP.

PHP strlen() function gives the length of a string.

Example :-

Output

 9

2) Count The Number of Words in a String PHP?

str_word_count() function is used to counts the number of words in a string..

Example :-

Output

 3

3) Replac Text within Strings in PHP

str_replace() function is used to replace the text given by user or replaces all occurrences of the text .

First Example :-

Output

 I amn't going. 

Second Example :-

Output

 The text was replaced 1 times. 

4) Reversing a String in PHP

PHP strrev() function is used to reverses a string:

Example :-

Output

 .gnihtyreve

Next Topic