PHP String

By Solve Program

PHP String

PHP Programming
PHP Programming

PHP is used for text data type like Hello World!. Example :



But string in PHP has more function like get the length of a string, count the number of words in a string, reverse string, search for a specific text within a string, replace text within a string.

Get the Length of a String

This code is used strlen() code. Example :



The output of code above is 12.

Count the Number of Words in a String

This code is used str_word_count() code. Example :



The output of code above is 2.

Reverse String

This code is used strrev() code. Example :



The output of code above is !dlrow olleH.

Search for a Specific Text Within a String

This code is used strpos() code. Example :



The output of code above is 6.

Replace Text Within a String

This code is used str_replace() code. Example :



The output of code above is Hello Bro!.