Your Ad Here

Posted By

adamturtle on 06/01/11


Tagged

php String sentences


Versions (?)

String to sentences function


 / Published in: PHP
 

A simple function that will split a given string into sentences, and then return the number of sentences specified. Quick and dirty.

  1. /*
  2. @param: $content - string to be returned
  3. @param: $sentences - number of sentences to return
  4. */
  5. function limit_sentences($content, $sentences) {
  6.  
  7. $text = html_entity_decode(strip_tags($content));
  8. $text = explode('.', $text);
  9. for( $i=1; $i<=$sentences; $i++ ){
  10. $output .= $text[$i] . '. ';
  11. }
  12. if($output){
  13. return $output;
  14. }
  15. else {
  16. return $content;
  17. }
  18. }

Report this snippet  

You need to login to post a comment.