note 68963 added to function.strlen
| From: | liquixathjelpesentraldotno at osu1 dot php dot net | Date: | Thu, 17 Aug 2006 12:57:15 +0000 |
| Subject: | note 68963 added to function.strlen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116007@lists.php.net to get a copy of this message | ||
An easy function to make sure the words in a sentence is not above the maximum lengt of characters.
This is used to prevent that users posting for an example comments on your page and drag the page
width out.
Returns true or false
<?php
function wordlength($txt, $limit)
{
$words = explode(' ', $txt);
foreach($words as $v)
{
if(strlen($v) > $limit)
{
return false;
}
}
return true;
}
?>
Uses like this:
<?php
$txt = "Onelongword and some small ones";
if(!wordlength($txt, 10))
{
die("One of the words where too long");
}
?>
That will return false since one of the words in $txt is too long. (Maximum set to 10)
----
Server IP: 83.137.200.2
Probable Submitter: 85.167.177.99
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.strlen.php
Edit -- https://master.php.net/note/edit/68963
Del: integrated -- https://master.php.net/note/delete/68963/integrated
Del: useless -- https://master.php.net/note/delete/68963/useless
Del: bad code -- https://master.php.net/note/delete/68963/bad+code
Del: spam -- https://master.php.net/note/delete/68963/spam
Del: non-english -- https://master.php.net/note/delete/68963/non-english
Del: in docs -- https://master.php.net/note/delete/68963/in+docs
Del: other reasons-- https://master.php.net/note/delete/68963
Reject -- https://master.php.net/note/reject/68963
Search -- https://master.php.net/manage/user-notes.php