wpp_phrase_spliter

The WooCommerce PDF & Print wpp phrase spliter function.

Description

wpp_phrase_spliter( $str, $length, (string) $merging_string = ' ', (bool) $return_first_part = true ); 

Parameters (4)

0. $str
The str.
1. $length
The length.
2. $merging_string — Optional. (string) => ' '
The merging string.
3. $return_first_part — Optional. (bool) => true
The return first part.

Usage

  1. if ( !function_exists( 'wpp_phrase_spliter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-pdf-print/functions.php'; 
  3.  
  4. // The str. 
  5. $str = null; 
  6.  
  7. // The length. 
  8. $length = null; 
  9.  
  10. // The merging string. 
  11. $merging_string = ' '; 
  12.  
  13. // The return first part. 
  14. $return_first_part = true; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wpp_phrase_spliter($str, $length, $merging_string, $return_first_part); 
  18.  

Defined (1)

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

/functions.php  
  1. function wpp_phrase_spliter( $str, $length, $merging_string = ' ', $return_first_part = true ) { 
  2. if( !$return_first_part ) { 
  3.  
  4. $str = str_replace(', ', ', ', $str ); 
  5. $array_1 = explode( ' ', $str); 
  6. foreach ($array_1 as $part_1) { 
  7. if( mb_strlen( $part_1, 'utf-8') > $length ) { 
  8. $string_array = str_split( $part_1, $length ); 
  9. $part_1 = implode( $merging_string, $string_array); 
  10. unset($string_array); 
  11. $new_string .= $part_1 .' '; 
  12. else { 
  13. if( mb_strlen( $str, 'utf-8') > $length ) { 
  14. $new_string = substr( $str, 0, $length ) .'...'; 
  15. else { 
  16. $new_string = $str; 
  17. return trim( $new_string );