note 54846 added to function.strlen

From: Date: Sun, 17 Jul 2005 12:49:59 +0000
Subject: note 54846 added to function.strlen
Groups: php.notes 
Request: Send a blank email to php-notes+get-92077@lists.php.net to get a copy of this message
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.'; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strlen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54846 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54846&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54846&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54846&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54846&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54846&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54846&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54846&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92077) next »