shortText function toggler in php

I often have to show a shortened version of a news item and then a link to show the entire news article or whatever.

Here’s a way to get that short text!

function shortText($text, $length) {
  if( strlen($text) > $length ) return substr(preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $text), 0, $length)."";
  return preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $text);
}
Tags:
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments