سؤال

I have created a form, a text box and a button. When I enter text into the text-box and click the button the text I entered is supposed to show up beneath the button which it does. My question would be how do you get the text when entered and outputted to also show up the amount of characters that the text consists of? I've looked on PHP.net that you can use strlen since that counts the amount of characters but for some reason my code wont work with this. I'm not looking for the answer I'm just looking for helpful advice of the next step I should take because I'm confused on what I'm doing wrong. Thanks for the help everyone.

 $count = strlen('');
     echo "The word has " . $count . " characters.<br />";
هل كانت مفيدة؟

المحلول

You count an empty string here: $count = strlen('');

Instead, you need the user input from your form. Show the code of the form.

Something like

$count = strlen($_POST['input_name']);

should work than.

Besides, updating live, while typing, is only possible with client side Javascript.

نصائح أخرى

lets say:

$text = $_POST["q"];
$count = strlen($text);
echo "The word has " . $count . " characters.<br />";
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top