bb_encoded_utf8_cut
The BuddyPress bb encoded utf8 cut function.
Description
Parameters (2)
- 0. $encoded
- The encoded.
- 1. $length — Optional. (int)
- The length.
Usage
if ( !function_exists( 'bb_encoded_utf8_cut' ) ) { require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-formatting.php'; } // The encoded. $encoded = null; // The length. $length = -1; // NOTICE! Understand what this does before running. $result = bb_encoded_utf8_cut($encoded, $length);
Defined (1)
The function is defined in the following location(s).
- /bp-forums/bbpress/bb-includes/functions.bb-formatting.php
- function bb_encoded_utf8_cut( $encoded, $length = 0 ) {
- if ( $length < 1 )
- return $encoded;
- $r = '';
- $values = preg_split( '/(%[0-9a-f]{2})/i', $encoded, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );;
- for ($i = 0; $i < count( $values ); $i += $num_octets ) {
- $num_octets = 1;
- if ( '%' != $values[$i][0] ) {
- $r .= $values[$i];
- if ( $length && strlen($r) > $length )
- return substr($r, 0, $length);
- } else {
- $value = hexdec(substr($values[$i], 1));
- if ( 1 == $num_octets )
- $num_octets = ( 224 > $value ) ? 2 : 3;
- if ( $length && ( strlen($r) + $num_octets * 3 ) > $length )
- return $r;
- $r .= $values[$i] . $values[$i + 1];
- if ( 3 == $num_octets )
- $r .= $values[$i + 2];
- }
- }
- return $r;
- }