Reputation: 21
I am in an entry level php course. The lesson is to create an HTML page with a textarea submit form in the essence of charging a customer for a classified ad using the number of words as the cost. That part is complete. The second page is a php script using str_word_count. How do you count the words in a textarea and then charge a price per word for every word over a set number?
Upvotes: 0
Views: 7955
Reputation:
How about just use $words= str_word_count($_POST['clientdetails']);
then, probably just do a simple maths like
$fee = $words * 0.50;
0.50 is the amount of money you are going to charge
then, something like:
<?php echo 'we are going to charge you '.$fee.' for these words'; ?>
Upvotes: 0
Reputation: 56
Here's the doc for str_word_count
Using it is really easy. For example if your textarea is named "mytextarea
" and you sent the form via POST (<form method="POST">
), your textarea data will be in$_POST['mytextarea']
Then counting the words :
$count = str_word_count($_POST['mytextarea']);
Then you just have to use the $count variable to do whatever you want.
Upvotes: 2
Reputation: 606
$var =textareaObject.value ; //Store textarea text in $var
print_r(str_word_count($var));
Upvotes: 0