nsTrnc

The NextScripts: Social Networks Auto-Poster nsTrnc function.

Description

nsTrnc( $string, $limit, (string) $break = ' ', (string) $pad = ' ...' ); 

Parameters (4)

0. $string
The string.
1. $limit
The limit.
2. $break — Optional. (string) => ' '
The break.
3. $pad — Optional. (string) => ' ...'
The pad.

Usage

  1. if ( !function_exists( 'nsTrnc' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/nxs_functions.php'; 
  3.  
  4. // The string. 
  5. $string = null; 
  6.  
  7. // The limit. 
  8. $limit = null; 
  9.  
  10. // The break. 
  11. $break = ' '; 
  12.  
  13. // The pad. 
  14. $pad = ' ...'; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = nsTrnc($string, $limit, $break, $pad); 
  18.  

Defined (1)

The function is defined in the following location(s).

/nxs_functions.php  
  1. if (!function_exists('nsTrnc')) { function nsTrnc($string, $limit, $break=" ", $pad=" ...") { if(nxs_strLen($string) <= $limit) return $string; if(nxs_strLen($pad) >= $limit) return ''; $string = nxs_substr($string, 0, $limit-nxs_strLen($pad));  
  2. $brLoc = strripos($string, $break); if ($brLoc===false) return $string.$pad; else return nxs_substr($string, 0, $brLoc).$pad;  
  3. }}