before_last_bar

Remove last item on a pipe-delimited string.

Description

(string) before_last_bar( (string) $string ); 

Meant for removing the last item in a string, such as Role name|User role.. The original string will be returned if no pipe | characters are found in the string.

Returns (string)

Either $string or everything before the last pipe.

Parameters (1)

0. $string (string)
A pipe-delimited string.

Usage

  1. if ( !function_exists( 'before_last_bar' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // A pipe-delimited string. 
  5. $string = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = before_last_bar($string); 
  9.  

Defined (1)

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

/wp-includes/l10n.php  
  1. function before_last_bar( $string ) { 
  2. $last_bar = strrpos( $string, '|' ); 
  3. if ( false === $last_bar ) { 
  4. return $string; 
  5. } else { 
  6. return substr( $string, 0, $last_bar );