App\Libraries\Str::head_and_tail PHP Method

head_and_tail() public static method

The start (head) and end (tail) of a string will be returned with an ellipsis between them where the text is cut.
public static head_and_tail ( $value, integer $limit = 100, string $mid = '...' ) : string
$value
$limit integer
$mid string
return string
    public static function head_and_tail($value, $limit = 100, $mid = '...')
    {
        $value_len = strlen($value);
        $mid_len = strlen($mid);
        $chunk_len = ($limit - $mid_len) / 2;
        $tail_start = $value_len - $chunk_len;
        if ($limit >= $value_len) {
            return $value;
        } else {
            $head = substr($value, 0, $chunk_len);
            $tail = substr($value, $tail_start);
            return $head . $mid . $tail;
        }
    }