Full width home advertisement

How To

Science

Post Page Advertisement [Top]


You have two simple steps:

1. Insert the HTML code in the search area on your webpage from <form action> element.

2. Create a php file, copy and paste the PHP code and name the file - search.php or any name you want to use and save.

3. Launch your html file or webpage in browser, make sure your wamp or xamp is on of you are on local server.



HTML FILE

<html> 
 <head>
<title>Search Form</title>
</head> 
 <body> <form action="search.php" method="GET"> <input type="text" name="keyword" id="keyword width="50" value="" /> <input type="submit" value="Search"/> </form> </body> 
</html>



PHP FILE

<?php
// script.php


$searchfor = $_GET['keyword'];

$file = 'users.txt';

$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*$pattern.*\$/m";

if(preg_match_all($pattern, $contents, $matches)){
   echo "Found matches:<br />";
   echo implode("<br />", $matches[0]);
}
else{
   echo "No matches found";
fclose ($file); 
}

?>



No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib