Categories
Php

Word Cutter function in PHP

In WordPress, it is very popular to show excerpt of a content which shows up to particular word limits.

In each and every cases it is not require to show the whole content rather than small content with limited words.

You may like:  Five PHP tech techniques to minimize web security vulnerabilities

Below function is an example of word limit or word cutter for a content.

function wordCutter($str,$len) {
 if(strlen(strip_tags(html_entity_decode($str)))>len)
 {
  $str = substr(strip_tags(html_entity_decode($str)),0,len);
  $pos   = strrpos($str," ");
  $str = substr(strip_tags(html_entity_decode($str)),0,$pos).'...';
 }
 else
 {
  $str = strip_tags(html_entity_decode($str));
 }
}
Avatar for Namaste UI

By Namaste UI

For any types of queries, you can contact us on info[at]namasteui.com.

Leave a Reply

Your email address will not be published. Required fields are marked *