String to sentences function


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. /*
  2. @param: $len - number of sentences to return
  3. @param: $content - string to be returned
  4. */
  5. function limit_sentences($len, $content){
  6. $content = preg_split('/[\.\!\?]\s{1}/',$content);
  7. $o = null;
  8. for($i=0;$i<$len;$i++){
  9. $o.= $content[$i] . '. ';
  10. }
  11. return $o;
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.