WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP 5 Strings


A string is an arrangement of characters, as "Hello PHP5! PHP underpins string operations".


PHP String Functions


Get The Length of a String

The PHP strlen() work restores the length of a string.

The precedent beneath returns the length of the string "Hello world!":

Example

<?php
reverberation strlen("Hello php!");/yields 15
?>

The yield of the code above will be: 15.


Count The Number of Words in a String

The PHP str_word_count() work include the quantity of words a string:

Example

<?php
reverberation str_word_count("Hello php!"); /yields 3
?>

The yield of the code above will be: 3.


Reverse a String

The PHP strrev() work turns around a string:

Example

<?php
reverberation strrev("Hello php!"); /yields !php olleH
?>

The yield of the code above will be: !phpolleH.


Search For a Specific Text Within a String

The PHP strpos() work scans for a particular content inside a string.

If a match is discovered, the capacity restores the character position of the primary match. On the off chance that no match is discovered, it will return FALSE.

The precedent beneath scans for the content "world" in the string "Hello world!":

Example

<?php
reverberation strpos("Hello php!", "php"); /yields 5
?>

The yield of the code above will be: 5.

Tip: The primary character position in a string is 0 (not 1).


Replace Text Within a String

The PHP str_replace() work replaces a few characters with some other characters in a string.

The model underneath replaces the content "world" with "Jully":

Example

<?php
reverberation str_replace("world", "Jully", "Hello world!"); /yields Hello Jully!
?>

The yield of the code above will be: Hello Jully!


Using the strpos() function

strpos() work is utilized to scan for a string or character inside a string.
 

<?php 

reverberation strpos("Hello world!","world"); 

?>