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); }
Code language: PHP (php)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments