Re: Simple search form to get status from external file
Posted: Mon Feb 06, 2012 5:37 pm
OK, I wasn't sure if you wanted to return partial matches or what you wanted to do when a match was found. Are you looking for something like this?
Code: Select all
<?php
if (!empty($_POST))
{
$serial = $_POST['serial_box_div']; //loads the var value
if (preg_match('/\d{5}/', $serial))
{
$file = @fopen("assitenciatecnica.txt", "r"); //read file
if ($file)
{ //validate file
while (!feof($file))
{
$line = fgets($file, 1024); //read line
if (preg_match('/^' . $serial . '/', $line))
{
$data = explode(' ', $line);
$id = rtrim($data[1], ';');
echo "<div id=\"id_{$id}\">Div id_{$id} created.</div>";
}
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Debug</title>
</head>
<body>
<form action="" method="post"><input name="serial_box_div" type="text" /> <input name="" type="submit" value="enviar"/></form>
</body>
</html>