2013-02-05 45 views
0

我是入門級php課程。我們的課程是創建一個帶有textarea提交表單的HTML頁面,其實質是以詞數作爲成本爲分類廣告收取客戶費用。那部分是完整的。第二頁是使用str_word_count的php腳本。如何計算textarea中的單詞,然後在每個單詞上爲每個單詞收取一定數量的費用?如何使用php str_word_count來計算textarea中的單詞

+0

你看過str_word_count()的手冊頁了嗎?你真的有什麼問題? –

+0

閱讀此:http://www.w3schools.com/php/func_string_str_word_count.asp –

+0

和這個:http://php.net/manual/en/function.str-word-count.php –

回答

2

下面是str_word_count

的文檔使用它是很容易。因爲如果你的textarea的被命名爲「mytextarea」,你通過POST(<form method="POST">)發送的形式,例如,您的textarea的數據將在$_POST['mytextarea']

然後計數的話:

$count = str_word_count($_POST['mytextarea']); 

然後你只需要使用$ count變量可以做任何你想做的事情。

+0

這樣做。謝謝! –

0
$var =textareaObject.value ; //Store textarea text in $var 

print_r(str_word_count($var)); 
0

如何只用$words= str_word_count($_POST['clientdetails']); 話,可能只是做一個簡單的數學像

$fee = $words * 0.50;

0.50是多少錢你要充電

然後,像:

<?php echo 'we are going to charge you '.$fee.' for these words'; ?>

相關問題