xoops_substr ( str,
start,
length,
trimmarker = '...' 
)

Returns the portion of string specified by the start and length parameters.

If $trimmarker is supplied, it is appended to the return string. This function works fine with multi-byte characters if mb_* functions exist on the server.

Parameters:
string $str
int $start
int $length
string $trimmarker
Returns:
string

Definition at line 591 of file functions.php.

References $action.

00592 {
00593     if ( !XOOPS_USE_MULTIBYTES ) {
00594         return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
00595     }
00596     if (function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) {
00597         $str2 = mb_strcut( $str , $start , $length - strlen( $trimmarker ) );
00598         return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
00599     }
00600     // phppp patch
00601     $DEP_CHAR=127;
00602     $pos_st=0;
00603     $action = false;
00604     for ( $pos_i = 0; $pos_i < strlen($str); $pos_i++ ) {
00605         if ( ord( substr( $str, $pos_i, 1) ) > 127 ) {
00606             $pos_i++;
00607         }
00608         if ($pos_i<=$start) {
00609             $pos_st=$pos_i;
00610         }
00611         if ($pos_i>=$pos_st+$length) {
00612             $action = true;
00613             break;
00614         }
00615     }
00616     return ($action) ? substr( $str, $pos_st, $pos_i - $pos_st - strlen($trimmarker) ) . $trimmarker : $str;
00617 }


Generated on Tue Jan 1 13:28:41 2008 for XOOPS by  doxygen 1.5.4