bb_sanitize_with_dashes

The BuddyPress bb sanitize with dashes function.

Description

bb_sanitize_with_dashes( $text, (int) $length = 0 ); 

Parameters (2)

0. $text
The text.
1. $length — Optional. (int)
The length.

Usage

  1. if ( !function_exists( 'bb_sanitize_with_dashes' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-formatting.php'; 
  3.  
  4. // The text. 
  5. $text = null; 
  6.  
  7. // The length. 
  8. $length = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_sanitize_with_dashes($text, $length); 
  12.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-formatting.php  
  1. function bb_sanitize_with_dashes( $text, $length = 0 ) { // Multibyte aware 
  2. $_text = $text; 
  3. $text = trim($text); 
  4. $text = strip_tags($text); 
  5. // Preserve escaped octets. 
  6. $text = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $text); 
  7. // Remove percent signs that are not part of an octet. 
  8. $text = str_replace('%', '', $text); 
  9. // Restore octets. 
  10. $text = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $text); 
  11.  
  12. $text = apply_filters( 'pre_sanitize_with_dashes', $text, $_text, $length ); 
  13.  
  14. $text = strtolower($text); 
  15. $text = preg_replace('/&(^\x80-\xff)+?;/', '', $text); // kill entities 
  16. $text = preg_replace('/[^%a-z0-9\x80-\xff _-]/', '', $text); 
  17. $text = trim($text); 
  18. $text = preg_replace('/\s+/', '-', $text); 
  19. $text = preg_replace(array('|-+|', '|_+|'), array('-', '_'), $text); // Kill the repeats 
  20.  
  21. return $text;