Posted By

DaveChild on 12/12/08


Tagged

php


Versions (?)


Advertising

Website Promotion DIRECTORY is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


Who likes this?

2 people have marked this snippet as a favorite

Slashman
Wardy


PHP Get First Characters of String in Complete Sentences


Published in: PHP 






URL: http://www.addedbytes.com/code/

Pass in text and the maximum allowable length and this snippet will return as many full sentences from the text as it can within that length. If no sentences, it will just trim to the maximum length allowed.

Expand | Embed | Plain Text
  1. function trim_text_in_sentences($intLength, $strText) {
  2. $intLastPeriodPos = strpos(strrev(substr($strText, 0, $intLength)), '.');
  3. if ($intLastPeriodPos === false) {
  4. $strReturn = substr($strText, 0, $intLength);
  5. } else {
  6. $strReturn = substr($strText, 0, ($intLength - $intLastPeriodPos));
  7. }
  8. return $strReturn;
  9. }

Report this snippet 

You need to login to post a comment.