English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Anyone know a PHP function that allows you to count characters in a text box?

I'd like to let users, who register on my website, know if the password or username they are trying to register is longer than, oh, say 8 characters.

I can't seem to find any function for this. I guess it would have to count the amount of characters within a variable.

2007-12-17 02:22:47 · 3 answers · asked by travo 1 in Computers & Internet Programming & Design

3 answers

If you want to stick with PHP rather than embedding the previously suggested Javascript, you should use the STRLEN function as documented here http://www.php.net/strlen

2007-12-17 02:43:23 · answer #1 · answered by Big Dave 5 · 0 0

You don't need to count.
You use strlen()
But you will have to use the trim() function to make sure that you have removed any leading or trailing spaces first.

2007-12-17 10:41:57 · answer #2 · answered by AnalProgrammer 7 · 0 0

If you just want to show the user how many characters they are typing, i would use something like this...

script type="text/javascript">
function countChar(str)
{
textcount = str.length + " characters typed";
document.getElementById('textCount') = textcount;
}




That way you don't have to reload the page

If you want to count the number of characters after the form is submitted you can use something like this...

if(isset($_POST['submit'])){

$name = $_POST['name'];
$namelength= count($name)
?>

2007-12-17 10:38:30 · answer #3 · answered by paula.underwood 2 · 0 0

fedest.com, questions and answers