PHP Snippets
Name:Length Limit
Description: Check to see if a string reach a certain limit. Useful to avoid flood or other abuse.
Code below...
>
<?php
//Text from a form
$message = $_POST['field_name'];
//Count numbers of character
$mlen = strlen($message);
//Maximum Length
$maxlen = 300;
//Message length is greater than maximum length
if ($mlen > $maxlen) {
echo "Message too long";
}
//Message length is less than maximum length
else {
echo "Good! Message received.";
}
?>
//Text from a form
$message = $_POST['field_name'];
//Count numbers of character
$mlen = strlen($message);
//Maximum Length
$maxlen = 300;
//Message length is greater than maximum length
if ($mlen > $maxlen) {
echo "Message too long";
}
//Message length is less than maximum length
else {
echo "Good! Message received.";
}
?>