2017-04-12 60 views
0

CKEDITOR:如果我传递了textarea的内容,我有一个表单和一个textarea(替换为ckeditor)如何获取wordcount值?我正在使用ckeditor中的wordcount插件。谢谢CKEDITOR:将wordcount值存储到变量

//how do i store the wordcount? 
 
    CKEDITOR.replace('textarea' , { 
 
    \t extraPlugins:'wordcount,justify' 
 
    }); 
 
//how do i get the wordcount ? 
 
<?= form_input($title,set_value('title')) . "</br>"; ?> 
 
<textarea name="textarea" id="text" required></textarea> 
 
<?= form_close(); ?> 
 

 
    //in php 
 
    $text = $this->input->post('textarea'); 
 
    //$textwordcount = wordcount of the textarea;

回答

0

也许你可以用我的招

$text = strip_tags($this->input->post('textarea')); 
$words = count(explode(' ',$text)); 
+0

我试图粘贴文件的价值(5430在wordcounter插件),但是当我用你的代码,它给了我5737点的话它统计输入/返回键作为一个单词。我也试过wordcounter.net它也给了我5430字,所以可能代码需要更多我猜 –

+0

$ text = strip_tags($ this-> input-> post('textarea')); $ text = trim(preg_replace('/ \ s + /','',$ text)); –

+0

它仍然计数输入/返回键作为一个词,也许因为即时通讯使用ckeditor和空格/返回/输入键意味着 我认为这样系统把它算作一个字 –