wc_trim_string

Trim a string and append a suffix.

Description

(string) wc_trim_string( (string) $string, (int) $chars = 200, (string) $suffix = '...' ); 

Returns (string)

Parameters (3)

0. $string (string)
The string.
1. $chars — Optional. (int) => 200
The chars.
2. $suffix — Optional. (string) => '...'
The suffix.

Usage

  1. if ( !function_exists( 'wc_trim_string' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php'; 
  3.  
  4. // The string. 
  5. $string = ''; 
  6.  
  7. // The chars. 
  8. $chars = 200; 
  9.  
  10. // The suffix. 
  11. $suffix = '...'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wc_trim_string($string, $chars, $suffix); 
  15.  

Defined (1)

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

/includes/wc-formatting-functions.php  
  1. function wc_trim_string( $string, $chars = 200, $suffix = '...' ) { 
  2. if ( strlen( $string ) > $chars ) { 
  3. if ( function_exists( 'mb_substr' ) ) { 
  4. $string = mb_substr( $string, 0, ( $chars - mb_strlen( $suffix ) ) ) . $suffix; 
  5. } else { 
  6. $string = substr( $string, 0, ( $chars - strlen( $suffix ) ) ) . $suffix; 
  7. return $string;