【问题标题】:How to use php str_word_count to count words in a textarea如何使用 php str_word_count 计算文本区域中的单词
【发布时间】:2013-01-20 11:09:25
【问题描述】:

我正在学习入门级 php 课程。课程是创建一个带有 textarea 提交表单的 HTML 页面,其本质是使用字数作为成本向客户收取分类广告费用。那部分是完整的。第二页是一个使用 str_word_count 的 php 脚本。您如何计算文本区域中的单词,然后对超过设定数量的每个单词按单词收费?

【问题讨论】:

标签: php textarea


【解决方案1】:

这是str_word_count 的文档

使用它真的很容易。例如,如果您的 textarea 名为“mytextarea”并且您通过 POST (<form method="POST">) 发送了表单,那么您的 textarea 数据将在$_POST['mytextarea']

然后数单词:

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

那么你只需要使用 $count 变量来做任何你想做的事情。

【讨论】:

    【解决方案2】:
    $var =textareaObject.value ; //Store textarea text in $var 
    
    print_r(str_word_count($var));
    

    【讨论】:

      【解决方案3】:

      使用$words= str_word_count($_POST['clientdetails']); 怎么样? 然后,可能只是做一个简单的数学,比如

      $fee = $words * 0.50;

      0.50 是您要收取的金额

      然后,类似:

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

      【讨论】:

        猜你喜欢
        • 2019-08-19
        • 2012-04-21
        • 1970-01-01
        • 2019-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多