input check
Posted: Fri Oct 17, 2003 9:02 pm
I want to check the user's input and if it's bigger then, say, 15 characters {... }
how can I do that?
how can I do that?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$input_lenght = strlen($user_input);//$user_input from a form maybe?
if($input_lenght > 15)
{
//do stuff
}
?>Code: Select all
<?php
/*
kriek at phpfreaks dot com
*/
function chopSent($varb, $num) {
$dNum = intval($num);
if (strlen($varb) > $dNum) {
$nVarb = substr($varb, 0, $dNum);
$nVarb .= '...';
}
elseif(strlen($varb) < $dNum) {
$nVarb = $varb;
}
return $nVarb;
}
// Usage of function
$theSent = 'PHP is a widely-used general-purpose scripting language';
$theSent = chopSent($theSent, 15);
echo $theSent;
?>Code: Select all
<?php
function cut_it($str, $num)
{
$length = strlen($str);
$return = $str;
if($length > $num)
{
$return = substr($str, -$length, $num)."...";
}
return $return;
}
//to use it
echo cut_it("PHP is a widely-used general-purpose scripting language", 10);
?>Code: Select all
<input type=text name=thisfield maxlength=15>if strlen<=15 is vital you have to check it server-side. clients should recognize the maxlength property but you cannot force them to do so.<input type=text name=thisfield maxlength=15>
that's also something not trustworthy if you refer to HTTP_REFER. The value is act of courtesy by the client and can be forged, too.you can also check if the server is the same as one in your code, so that way u don't have to check for every value