An example
1, index.php
<metahttp-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> detect the length of the string </title>
<styletype= "Text/css" >
<!--
. style1 {font-size:12px}
. style2 {
Font-family: "XXFarEastFont-Imitation";
font-size:14px;
}
Body {
margin-left:00px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
}
. STYLE3 {color: #FF0000}
-->
</style>
<body>
<tablewidth= "392" height= "257" border= "0" cellpadding= "0" cellspacing= "0" >
<tr>
<tdalign= "left" valign= "top" ><tablewidth= "392" border= "0" cellpadding= "0"
cellspacing= "0" >
<tr>
<tdwidth= "height=" "113" > </td>
<tdwidth= "> </td>"
<tdwidth= "119" > </td>
<tdwidth= "a" > </td>
<tdwidth= "align=" "Center" class= "Style1" > </td>
</tr>
<formname= "Form1" method= "Post" action= "index_ok.php" >
<tr>
<tdheight= "></td>"
<tdalign= "center" ><spanclass= "Style1" > Username </span>:</td>
<td><inputname= "User" type= "text" id= "user" size= "></td>"
<tdalign= "center" ><inputname= "ImageField" type= "image"
Src= "Images/btn_dl.jpg" width= "height=" border= "0" ></td>
<td> </td>
</tr>
<tr>
<tdheight= "> </td>"
<tdalign= "center" ><spanclass= "Style1" > Password </span>:</td>
<td><inputname= "pwd" type= "password" id= "pass" size= "></td>"
<tdcolspan= "2" align= "left" ><spanclass= "STYLE3" >* password length cannot be less than 6 digits
</span></td>
</tr>
</form>
<tr>
<tdheight= "> </td>"
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
2, index_ok.php
if (strlen ($_post["pwd"]) <6) {//Detect user password length less than 6
echo "<script>alert (' user password must not be less than 6 bits in length!"); History.back ();</script> ";
}
else{
echo "User information input Legal! ";
}
?>
Two running results
int strlen (String $string)
Returns the length of a given string of strings.
Parameters
String
A string that needs to be computed for length.
return value
Success returns the length of string strings, or 0 if the string is empty.
Source: http://cakin24.iteye.com/blog/2348826