PHP Programs

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 47: Write a Program to find the duplicate words in a string.


<!DOCTYPE html>  
	<title>PHP Programs</title>
		$str = " is a witty content portal <br >that is optimized for college students <br>which mainly focuses on Computer Science <br> Subjects. Our aim to provide easily <br> accessible and well organised quality content <br> 		to all the students.";  

		echo "Original string is  :- <br> <br> ". $str;
		$str = strtolower($str);  
		$words = explode(" ", $str);  

		echo "Duplicate words in a given string are :- <br>";  
		for($i = 0; $i < count($words); $i++) 
			$count = 1;  
			for($j = $i+1; $j < count($words); $j++) 
				if($words[$i] == $words[$j]) 
					$words[$j] = "0";  
			if($count > 1 && $words[$i] != "0")
				echo $words[$i];  
				echo "<br>";  

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.