note 54846 deleted from function.strlen by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 12:12:38 +0000 |
| Subject: | note 54846 deleted from function.strlen by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189611@lists.php.net to get a copy of this message | ||
Note Submitter: triadsebas at triads dot buildtolearn dot net
----
A nice use of the strlen() function, the following function will check if one of the words in $input
is longer than $maxlenght, $maxlenght is standard 40.
<?php
function check_input($input, $maxlenght= 40)
$temp_array = explode(" ", $input);
foreach ($temp_array as $word) {
if (strlen($word) > $maxlenght) {
return false;
}
}
return true;
}
?>
Example:
<?php
if (!check_input($_POST['message'])) {
print 'One of your words in your message in longer than 40 chars. Please edit your
message.';
}
?>