Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-------------------------------------------------------------------------------
- Truncate Function For Excerpts
- -------------------------------------------------------------------------------*/
- function trunc($phrase, $max_words) {
- $phrase_array = explode(' ',$phrase);
- if(count($phrase_array) > $max_words && $max_words > 0) {
- $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).' … ';
- }
- return $phrase;
- }
- // Original PHP code by Chirp Internet: www.chirp.com.au
- // Please acknowledge use of this code by including this header.
- function restoreTags($input)
- {
- $opened = array();
- // loop through opened and closed tags in order
- if(preg_match_all("/<(\/?[a-z]+)>?/i", $input, $matches)) {
- foreach($matches[1] as $tag) {
- if(preg_match("/^[a-z]+$/i", $tag, $regs)) {
- // a tag has been opened
- if(strtolower($regs[0]) != 'br') $opened[] = $regs[0];
- } elseif(preg_match("/^\/([a-z]+)$/i", $tag, $regs)) {
- // a tag has been closed
- unset($opened[array_pop(array_keys($opened, $regs[1]))]);
- }
- }
- }
- // close tags that are still open
- if($opened) {
- $tagstoclose = array_reverse($opened);
- foreach($tagstoclose as $tag) $input .= "</$tag>";
- }
- return $input;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement