LERAN PHP COMPLETE

Learn one of the most powerful programming languages in the world and become a rockstar developer.

PhP Strings


A string is a sequence of characters, like "Hello world!".

Get The Length of a String

In PHP, the strlen() function returns the length of a string.

<?php
    echo strlen("Hello world!");  //this gives output 12
?>

Count The Number of Words in a String

In PHP, the str_word_count() function returns the number of words in a string.

<?php
    echo str_word_count("Hello world!");  /this gives output 2
?>

Reverse a String

In PHP, the strrev() function reverse a string.

<?php
    echo strrev("Hello world!"); // output :  !dlrow olleH
?>

Search For a Specific Text Within a String

In PHP, the strpos() function return a postion of letter or word in string. If not found then return FALSE

<?php
    echo strpos("Hello world!", "world");  //this give output 6
?>

Tips: The first character position in a string is 0 (not 1).

Replace text Within a String

In PHP, the str_replace() function replace the string within a string

<?php
    echo str_replace("world", "Adzetech", "Hello world!");  //output is : Hello Adzetech!
?>

x
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Privacy Policy That's Fine