PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 11: Write a PHP program that checks if a string contains another string.

string.php

<!DOCTYPE html>
<html>
<head>
	<title>PHP Programs TutorialDuniya.com</title>
</head>
<body>
	<form method="GET" action="">
		Enter a string : <input type="Text" name="string1"><br/>
		Enter a substr : <input type="Text" name="string2"><br/>
		<input type="Submit" value="submit">
	</form>

	<?php
		if(isset($_GET["string1"])&&isset($_GET["string2"])) 
		{
			$str1 =$_GET["string1"];
			$str2 =$_GET["string2"];

			echo "the string is :<br/> $str1 <br/>";
			echo "the substring is :<br/> $str2 ";

			if (strchr($str1,$str2))
				echo "<br/> The string contains the substring"; 
			else
				echo "<br/> The string doesn't contain the substring";
		}
	?>
</body>
</html>



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.