Counting, Reversing, And Repeating String

We are gonna have some fun with string in PHP. Let's check it out!

All right! We will learn how to count number of characters or words, reversing, and repeating a string. It's easy because, we are just gonna use the predefined functin in PHP.

$s="What a nice day";
echo strlen($s)."<br>"; //counts number of characters in string including spaces
echo str_word_count($s)."<br>"; //counts number of words in string or sentence
echo strrev($s)."<br>"; //reversing the string
echo str_repeat($s, 2); //repeating string a number of times. in this example, we repeat it 2 times.
echo "<p>";

You can copy and paste the coding above or try it by using PHP online compiler HERE. Good Luck!

Labels: , , , , , , , , , , , , ,