PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/bblog/smarty_plugins/modifier.count_sentences.php

https://github.com/escherlat/loquacity
PHP | 31 lines | 5 code | 5 blank | 21 comment | 0 complexity | e2beb3773c42bff28e3bc522541c033b MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. * Smarty plugin
  4. *
  5. * @subpackage plugins
  6. * @package Smarty
  7. */
  8. /**
  9. * Smarty count_sentences modifier plugin
  10. *
  11. * Type: modifier<br>
  12. * Name: count_sentences
  13. * Purpose: count the number of sentences in a text
  14. *
  15. * @link http://smarty.php.net/manual/en/language.modifier.count.paragraphs.php
  16. * count_sentences (Smarty online manual)
  17. * @param string
  18. * @param unknown $string
  19. * @return integer
  20. */
  21. function smarty_modifier_count_sentences($string) {
  22. // find periods with a word before but not after.
  23. return preg_match_all('/[^\s]\.(?!\w)/', $string, $match);
  24. }
  25. /* vim: set expandtab: */
  26. ?>