Trim a text - Php

trim_text

Snippet Code


  
Rate this page :
  [ 0 votes]

This function is used to trim a long text using php.

public function trim_text($text, $words = 50) { $matches = preg_split("/s /", $text, $words 1); $sz = count($matches); if ($sz > $words) { unset($matches[$sz-1]); return implode(' ',$matches)." ..."; } return $text; }

Tags


Ask Questions

Ask Question