note 68963 deleted from function.strlen by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 12:13:31 +0000 |
| Subject: | note 68963 deleted from function.strlen by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189613@lists.php.net to get a copy of this message | ||
Note Submitter: liquix at hjelpesentral dot no
----
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)