194. PHP Program to find the Position of a Word in given string.
How does this program work?
- In this program you are going to learn about to find the position of a word in given string using PHP.
Here is the code
<html>
<head>
<title>PHP Program To find the position of a word in given string</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text<" name="num1" value="" placeholder="Enter a String"/> </td>
</tr>
<tr>
<td> <input type="text" name="num2" value="" placeholder="Enter search word"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$str = $_POST['num1'];
$name = $_POST['num2'];
$pos=strpos($str,$name); //To find the position of a word inside the string $pos = strpos(<$str,$name);
echo "Given string: ".$str."</br>";
echo "Search word: ".$name."</br>";
echo "The Word is found in the String at ".$pos ." position";
return 0;
}
?>
</body>
</html>