php

How to count repeated words in a string in PHP

In this tutorial, we are going to see how to count repeated words in a string in PHP. You can use PHP’s substr_count() function to find out how many times a given substring appears or is repeated in a string.
 

How to count repeated words in a string in PHP
<?php
	$str = "Welcom to StackHowTo, StackHowTo is the best website for learning";
	 
	echo substr_count($str, 'StackHowTo');
?>

Output:

2

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *