How would I incorporate a function to simply check the "name" and "message" for a certain amount of chars, like 15 & 150?
<form method="post" action="chat.php">
<p><input name="name" type="text" id="name" value="your name" size="10" maxlength="15">
<input name="message" type="text" id="message" value="your message" size="20" maxlength="150">
<input name="submit" type="submit" id="submit"></p>
</form>
</body>
</html>
<?php
// when the submit button is clicked
if(isset($_POST['submit']))
{
// strip any html tags before continuing
$name=strip_tags($_POST['name']);
$message=strip_tags($_POST['message']);
// stop if nothing was entered
if($name!='')
if($message!='')
{
// trim any extra whitespace
$data=trim($name)."\n";
$data.=trim($message)."\n";
//open the text file and enter the data
$file_ar=file("db.txt");
$fp=fopen("db.txt","w");
fputs($fp,$data);
if($file_ar!=NULL)
{
$loop=0;
foreach($file_ar as $line)
{
// do not store more than 20 messages
if($loop>=19*3) break;
fputs($fp,$line);
$loop++;
}
}
fclose($fp);
}
}
// display the messages
$fp=fopen("db.txt","r");
while(!feof($fp))
{
$name=trim(fgets($fp,999));
$message=trim(fgets($fp,999));
if($name!='')
{
echo "<p><b>$name: </b>$message</p>";
}
}
fclose($fp);
?>