ci4

Форк
0
/
text_helper.php 
748 строк · 23.3 Кб
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
use Config\ForeignCharacters;
15

16
// CodeIgniter Text Helpers
17

18
if (! function_exists('word_limiter')) {
19
    /**
20
     * Word Limiter
21
     *
22
     * Limits a string to X number of words.
23
     *
24
     * @param string $endChar the end character. Usually an ellipsis
25
     */
26
    function word_limiter(string $str, int $limit = 100, string $endChar = '&#8230;'): string
27
    {
28
        if (trim($str) === '') {
29
            return $str;
30
        }
31

32
        preg_match('/^\s*+(?:\S++\s*+){1,' . $limit . '}/', $str, $matches);
33

34
        if (strlen($str) === strlen($matches[0])) {
35
            $endChar = '';
36
        }
37

38
        return rtrim($matches[0]) . $endChar;
39
    }
40
}
41

42
if (! function_exists('character_limiter')) {
43
    /**
44
     * Character Limiter
45
     *
46
     * Limits the string based on the character count.  Preserves complete words
47
     * so the character count may not be exactly as specified.
48
     *
49
     * @param string $endChar the end character. Usually an ellipsis
50
     */
51
    function character_limiter(string $str, int $n = 500, string $endChar = '&#8230;'): string
52
    {
53
        if (mb_strlen($str) < $n) {
54
            return $str;
55
        }
56

57
        // a bit complicated, but faster than preg_replace with \s+
58
        $str = preg_replace('/ {2,}/', ' ', str_replace(["\r", "\n", "\t", "\x0B", "\x0C"], ' ', $str));
59

60
        if (mb_strlen($str) <= $n) {
61
            return $str;
62
        }
63

64
        $out = '';
65

66
        foreach (explode(' ', trim($str)) as $val) {
67
            $out .= $val . ' ';
68
            if (mb_strlen($out) >= $n) {
69
                $out = trim($out);
70
                break;
71
            }
72
        }
73

74
        return (mb_strlen($out) === mb_strlen($str)) ? $out : $out . $endChar;
75
    }
76
}
77

78
if (! function_exists('ascii_to_entities')) {
79
    /**
80
     * High ASCII to Entities
81
     *
82
     * Converts high ASCII text and MS Word special characters to character entities
83
     */
84
    function ascii_to_entities(string $str): string
85
    {
86
        $out = '';
87

88
        for ($i = 0, $s = strlen($str) - 1, $count = 1, $temp = []; $i <= $s; $i++) {
89
            $ordinal = ord($str[$i]);
90

91
            if ($ordinal < 128) {
92
                /*
93
                  If the $temp array has a value but we have moved on, then it seems only
94
                  fair that we output that entity and restart $temp before continuing.
95
                 */
96
                if (count($temp) === 1) {
97
                    $out .= '&#' . array_shift($temp) . ';';
98
                    $count = 1;
99
                }
100

101
                $out .= $str[$i];
102
            } else {
103
                if ($temp === []) {
104
                    $count = ($ordinal < 224) ? 2 : 3;
105
                }
106

107
                $temp[] = $ordinal;
108

109
                if (count($temp) === $count) {
110
                    $number = ($count === 3) ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64) : (($temp[0] % 32) * 64) + ($temp[1] % 64);
111
                    $out .= '&#' . $number . ';';
112
                    $count = 1;
113
                    $temp  = [];
114
                }
115
                // If this is the last iteration, just output whatever we have
116
                elseif ($i === $s) {
117
                    $out .= '&#' . implode(';', $temp) . ';';
118
                }
119
            }
120
        }
121

122
        return $out;
123
    }
124
}
125

126
if (! function_exists('entities_to_ascii')) {
127
    /**
128
     * Entities to ASCII
129
     *
130
     * Converts character entities back to ASCII
131
     */
132
    function entities_to_ascii(string $str, bool $all = true): string
133
    {
134
        if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
135
            for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
136
                $digits = (int) $matches[1][$i];
137
                $out    = '';
138
                if ($digits < 128) {
139
                    $out .= chr($digits);
140
                } elseif ($digits < 2048) {
141
                    $out .= chr(192 + (($digits - ($digits % 64)) / 64)) . chr(128 + ($digits % 64));
142
                } else {
143
                    $out .= chr(224 + (($digits - ($digits % 4096)) / 4096))
144
                            . chr(128 + ((($digits % 4096) - ($digits % 64)) / 64))
145
                            . chr(128 + ($digits % 64));
146
                }
147
                $str = str_replace($matches[0][$i], $out, $str);
148
            }
149
        }
150

151
        if ($all) {
152
            return str_replace(
153
                ['&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'],
154
                ['&', '<', '>', '"', "'", '-'],
155
                $str
156
            );
157
        }
158

159
        return $str;
160
    }
161
}
162

163
if (! function_exists('word_censor')) {
164
    /**
165
     * Word Censoring Function
166
     *
167
     * Supply a string and an array of disallowed words and any
168
     * matched words will be converted to #### or to the replacement
169
     * word you've submitted.
170
     *
171
     * @param string $str         the text string
172
     * @param array  $censored    the array of censored words
173
     * @param string $replacement the optional replacement value
174
     */
175
    function word_censor(string $str, array $censored, string $replacement = ''): string
176
    {
177
        if ($censored === []) {
178
            return $str;
179
        }
180

181
        $str = ' ' . $str . ' ';
182

183
        // \w, \b and a few others do not match on a unicode character
184
        // set for performance reasons. As a result words like über
185
        // will not match on a word boundary. Instead, we'll assume that
186
        // a bad word will be bookended by any of these characters.
187
        $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
188

189
        foreach ($censored as $badword) {
190
            $badword = str_replace('\*', '\w*?', preg_quote($badword, '/'));
191

192
            if ($replacement !== '') {
193
                $str = preg_replace(
194
                    "/({$delim})(" . $badword . ")({$delim})/i",
195
                    "\\1{$replacement}\\3",
196
                    $str
197
                );
198
            } elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
199
                $matches = $matches[1];
200

201
                for ($i = count($matches) - 1; $i >= 0; $i--) {
202
                    $length = strlen($matches[$i][0]);
203

204
                    $str = substr_replace(
205
                        $str,
206
                        str_repeat('#', $length),
207
                        $matches[$i][1],
208
                        $length
209
                    );
210
                }
211
            }
212
        }
213

214
        return trim($str);
215
    }
216
}
217

218
if (! function_exists('highlight_code')) {
219
    /**
220
     * Code Highlighter
221
     *
222
     * Colorizes code strings
223
     *
224
     * @param string $str the text string
225
     */
226
    function highlight_code(string $str): string
227
    {
228
        /* The highlight string function encodes and highlights
229
         * brackets so we need them to start raw.
230
         *
231
         * Also replace any existing PHP tags to temporary markers
232
         * so they don't accidentally break the string out of PHP,
233
         * and thus, thwart the highlighting.
234
         */
235
        $str = str_replace(
236
            ['&lt;', '&gt;', '<?', '?>', '<%', '%>', '\\', '</script>'],
237
            ['<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'],
238
            $str
239
        );
240

241
        // The highlight_string function requires that the text be surrounded
242
        // by PHP tags, which we will remove later
243
        $str = highlight_string('<?php ' . $str . ' ?>', true);
244

245
        // Remove our artificially added PHP, and the syntax highlighting that came with it
246
        $str = preg_replace(
247
            [
248
                '/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i',
249
                '/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is',
250
                '/<span style="color: #[A-Z0-9]+"\><\/span>/i',
251
            ],
252
            [
253
                '<span style="color: #$1">',
254
                "$1</span>\n</span>\n</code>",
255
                '',
256
            ],
257
            $str
258
        );
259

260
        // Replace our markers back to PHP tags.
261
        return str_replace(
262
            [
263
                'phptagopen',
264
                'phptagclose',
265
                'asptagopen',
266
                'asptagclose',
267
                'backslashtmp',
268
                'scriptclose',
269
            ],
270
            [
271
                '&lt;?',
272
                '?&gt;',
273
                '&lt;%',
274
                '%&gt;',
275
                '\\',
276
                '&lt;/script&gt;',
277
            ],
278
            $str
279
        );
280
    }
281
}
282

283
if (! function_exists('highlight_phrase')) {
284
    /**
285
     * Phrase Highlighter
286
     *
287
     * Highlights a phrase within a text string
288
     *
289
     * @param string $str      the text string
290
     * @param string $phrase   the phrase you'd like to highlight
291
     * @param string $tagOpen  the opening tag to precede the phrase with
292
     * @param string $tagClose the closing tag to end the phrase with
293
     */
294
    function highlight_phrase(string $str, string $phrase, string $tagOpen = '<mark>', string $tagClose = '</mark>'): string
295
    {
296
        return ($str !== '' && $phrase !== '') ? preg_replace('/(' . preg_quote($phrase, '/') . ')/i', $tagOpen . '\\1' . $tagClose, $str) : $str;
297
    }
298
}
299

300
if (! function_exists('convert_accented_characters')) {
301
    /**
302
     * Convert Accented Foreign Characters to ASCII
303
     *
304
     * @param string $str Input string
305
     */
306
    function convert_accented_characters(string $str): string
307
    {
308
        static $arrayFrom, $arrayTo;
309

310
        if (! is_array($arrayFrom)) {
311
            $config = new ForeignCharacters();
312

313
            if ($config->characterList === [] || ! is_array($config->characterList)) {
314
                $arrayFrom = [];
315
                $arrayTo   = [];
316

317
                return $str;
318
            }
319
            $arrayFrom = array_keys($config->characterList);
320
            $arrayTo   = array_values($config->characterList);
321

322
            unset($config);
323
        }
324

325
        return preg_replace($arrayFrom, $arrayTo, $str);
326
    }
327
}
328

329
if (! function_exists('word_wrap')) {
330
    /**
331
     * Word Wrap
332
     *
333
     * Wraps text at the specified character. Maintains the integrity of words.
334
     * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
335
     * will URLs.
336
     *
337
     * @param string $str     the text string
338
     * @param int    $charlim = 76    the number of characters to wrap at
339
     */
340
    function word_wrap(string $str, int $charlim = 76): string
341
    {
342
        // Reduce multiple spaces
343
        $str = preg_replace('| +|', ' ', $str);
344

345
        // Standardize newlines
346
        if (str_contains($str, "\r")) {
347
            $str = str_replace(["\r\n", "\r"], "\n", $str);
348
        }
349

350
        // If the current word is surrounded by {unwrap} tags we'll
351
        // strip the entire chunk and replace it with a marker.
352
        $unwrap = [];
353

354
        if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
355
            for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
356
                $unwrap[] = $matches[1][$i];
357
                $str      = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);
358
            }
359
        }
360

361
        // Use PHP's native function to do the initial wordwrap.
362
        // We set the cut flag to FALSE so that any individual words that are
363
        // too long get left alone. In the next step we'll deal with them.
364
        $str = wordwrap($str, $charlim, "\n", false);
365

366
        // Split the string into individual lines of text and cycle through them
367
        $output = '';
368

369
        foreach (explode("\n", $str) as $line) {
370
            // Is the line within the allowed character count?
371
            // If so we'll join it to the output and continue
372
            if (mb_strlen($line) <= $charlim) {
373
                $output .= $line . "\n";
374

375
                continue;
376
            }
377

378
            $temp = '';
379

380
            while (mb_strlen($line) > $charlim) {
381
                // If the over-length word is a URL we won't wrap it
382
                if (preg_match('!\[url.+\]|://|www\.!', $line)) {
383
                    break;
384
                }
385
                // Trim the word down
386
                $temp .= mb_substr($line, 0, $charlim - 1);
387
                $line = mb_substr($line, $charlim - 1);
388
            }
389

390
            // If $temp contains data it means we had to split up an over-length
391
            // word into smaller chunks so we'll add it back to our current line
392
            if ($temp !== '') {
393
                $output .= $temp . "\n" . $line . "\n";
394
            } else {
395
                $output .= $line . "\n";
396
            }
397
        }
398

399
        // Put our markers back
400
        foreach ($unwrap as $key => $val) {
401
            $output = str_replace('{{unwrapped' . $key . '}}', $val, $output);
402
        }
403

404
        // remove any trailing newline
405
        return rtrim($output);
406
    }
407
}
408

409
if (! function_exists('ellipsize')) {
410
    /**
411
     * Ellipsize String
412
     *
413
     * This function will strip tags from a string, split it at its max_length and ellipsize
414
     *
415
     * @param string    $str       String to ellipsize
416
     * @param int       $maxLength Max length of string
417
     * @param float|int $position  int (1|0) or float, .5, .2, etc for position to split
418
     * @param string    $ellipsis  ellipsis ; Default '...'
419
     *
420
     * @return string Ellipsized string
421
     */
422
    function ellipsize(string $str, int $maxLength, $position = 1, string $ellipsis = '&hellip;'): string
423
    {
424
        // Strip tags
425
        $str = trim(strip_tags($str));
426

427
        // Is the string long enough to ellipsize?
428
        if (mb_strlen($str) <= $maxLength) {
429
            return $str;
430
        }
431

432
        $beg      = mb_substr($str, 0, (int) floor($maxLength * $position));
433
        $position = ($position > 1) ? 1 : $position;
434

435
        if ($position === 1) {
436
            $end = mb_substr($str, 0, -($maxLength - mb_strlen($beg)));
437
        } else {
438
            $end = mb_substr($str, -($maxLength - mb_strlen($beg)));
439
        }
440

441
        return $beg . $ellipsis . $end;
442
    }
443
}
444

445
if (! function_exists('strip_slashes')) {
446
    /**
447
     * Strip Slashes
448
     *
449
     * Removes slashes contained in a string or in an array
450
     *
451
     * @param array|string $str string or array
452
     *
453
     * @return array|string string or array
454
     */
455
    function strip_slashes($str)
456
    {
457
        if (! is_array($str)) {
458
            return stripslashes($str);
459
        }
460

461
        foreach ($str as $key => $val) {
462
            $str[$key] = strip_slashes($val);
463
        }
464

465
        return $str;
466
    }
467
}
468

469
if (! function_exists('strip_quotes')) {
470
    /**
471
     * Strip Quotes
472
     *
473
     * Removes single and double quotes from a string
474
     */
475
    function strip_quotes(string $str): string
476
    {
477
        return str_replace(['"', "'"], '', $str);
478
    }
479
}
480

481
if (! function_exists('quotes_to_entities')) {
482
    /**
483
     * Quotes to Entities
484
     *
485
     * Converts single and double quotes to entities
486
     */
487
    function quotes_to_entities(string $str): string
488
    {
489
        return str_replace(["\\'", '"', "'", '"'], ['&#39;', '&quot;', '&#39;', '&quot;'], $str);
490
    }
491
}
492

493
if (! function_exists('reduce_double_slashes')) {
494
    /**
495
     * Reduce Double Slashes
496
     *
497
     * Converts double slashes in a string to a single slash,
498
     * except those found in http://
499
     *
500
     * http://www.some-site.com//index.php
501
     *
502
     * becomes:
503
     *
504
     * http://www.some-site.com/index.php
505
     */
506
    function reduce_double_slashes(string $str): string
507
    {
508
        return preg_replace('#(^|[^:])//+#', '\\1/', $str);
509
    }
510
}
511

512
if (! function_exists('reduce_multiples')) {
513
    /**
514
     * Reduce Multiples
515
     *
516
     * Reduces multiple instances of a particular character.  Example:
517
     *
518
     * Fred, Bill,, Joe, Jimmy
519
     *
520
     * becomes:
521
     *
522
     * Fred, Bill, Joe, Jimmy
523
     *
524
     * @param string $character the character you wish to reduce
525
     * @param bool   $trim      TRUE/FALSE - whether to trim the character from the beginning/end
526
     */
527
    function reduce_multiples(string $str, string $character = ',', bool $trim = false): string
528
    {
529
        $pattern = '#' . preg_quote($character, '#') . '{2,}#';
530
        $str     = preg_replace($pattern, $character, $str);
531

532
        return $trim ? trim($str, $character) : $str;
533
    }
534
}
535

536
if (! function_exists('random_string')) {
537
    /**
538
     * Create a Random String
539
     *
540
     * Useful for generating passwords or hashes.
541
     *
542
     * @param string $type Type of random string.  basic, alpha, alnum, numeric, nozero, md5, sha1, and crypto
543
     * @param int    $len  Number of characters
544
     *
545
     * @deprecated The type 'basic', 'md5', and 'sha1' are deprecated. They are not cryptographically secure.
546
     */
547
    function random_string(string $type = 'alnum', int $len = 8): string
548
    {
549
        switch ($type) {
550
            case 'alnum':
551
            case 'nozero':
552
            case 'alpha':
553
                switch ($type) {
554
                    case 'alpha':
555
                        $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
556
                        break;
557

558
                    case 'alnum':
559
                        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
560
                        break;
561

562
                    case 'nozero':
563
                        $pool = '123456789';
564
                        break;
565
                }
566

567
                return _from_random($len, $pool);
568

569
            case 'numeric':
570
                $max  = 10 ** $len - 1;
571
                $rand = random_int(0, $max);
572

573
                return sprintf('%0' . $len . 'd', $rand);
574

575
            case 'md5':
576
                return md5(uniqid((string) mt_rand(), true));
577

578
            case 'sha1':
579
                return sha1(uniqid((string) mt_rand(), true));
580

581
            case 'crypto':
582
                if ($len % 2 !== 0) {
583
                    throw new InvalidArgumentException(
584
                        'You must set an even number to the second parameter when you use `crypto`.'
585
                    );
586
                }
587

588
                return bin2hex(random_bytes($len / 2));
589
        }
590

591
        // 'basic' type treated as default
592
        return (string) mt_rand();
593
    }
594
}
595

596
if (! function_exists('_from_random')) {
597
    /**
598
     * The following function was derived from code of Symfony (v6.2.7 - 2023-02-28)
599
     * https://github.com/symfony/symfony/blob/80cac46a31d4561804c17d101591a4f59e6db3a2/src/Symfony/Component/String/ByteString.php#L45
600
     * Code subject to the MIT license (https://github.com/symfony/symfony/blob/v6.2.7/LICENSE).
601
     * Copyright (c) 2004-present Fabien Potencier
602
     *
603
     * The following method was derived from code of the Hack Standard Library (v4.40 - 2020-05-03)
604
     * https://github.com/hhvm/hsl/blob/80a42c02f036f72a42f0415e80d6b847f4bf62d5/src/random/private.php#L16
605
     * Code subject to the MIT license (https://github.com/hhvm/hsl/blob/master/LICENSE).
606
     * Copyright (c) 2004-2020, Facebook, Inc. (https://www.facebook.com/)
607
     *
608
     * @internal Outside the framework this should not be used directly.
609
     */
610
    function _from_random(int $length, string $pool): string
611
    {
612
        if ($length <= 0) {
613
            throw new InvalidArgumentException(
614
                sprintf('A strictly positive length is expected, "%d" given.', $length)
615
            );
616
        }
617

618
        $poolSize = \strlen($pool);
619
        $bits     = (int) ceil(log($poolSize, 2.0));
620
        if ($bits <= 0 || $bits > 56) {
621
            throw new InvalidArgumentException(
622
                'The length of the alphabet must in the [2^1, 2^56] range.'
623
            );
624
        }
625

626
        $string = '';
627

628
        while ($length > 0) {
629
            $urandomLength = (int) ceil(2 * $length * $bits / 8.0);
630
            $data          = random_bytes($urandomLength);
631
            $unpackedData  = 0;
632
            $unpackedBits  = 0;
633

634
            for ($i = 0; $i < $urandomLength && $length > 0; $i++) {
635
                // Unpack 8 bits
636
                $unpackedData = ($unpackedData << 8) | \ord($data[$i]);
637
                $unpackedBits += 8;
638

639
                // While we have enough bits to select a character from the alphabet, keep
640
                // consuming the random data
641
                for (; $unpackedBits >= $bits && $length > 0; $unpackedBits -= $bits) {
642
                    $index = ($unpackedData & ((1 << $bits) - 1));
643
                    $unpackedData >>= $bits;
644
                    // Unfortunately, the alphabet size is not necessarily a power of two.
645
                    // Worst case, it is 2^k + 1, which means we need (k+1) bits and we
646
                    // have around a 50% chance of missing as k gets larger
647
                    if ($index < $poolSize) {
648
                        $string .= $pool[$index];
649
                        $length--;
650
                    }
651
                }
652
            }
653
        }
654

655
        return $string;
656
    }
657
}
658

659
if (! function_exists('increment_string')) {
660
    /**
661
     * Add's _1 to a string or increment the ending number to allow _2, _3, etc
662
     *
663
     * @param string $str       Required
664
     * @param string $separator What should the duplicate number be appended with
665
     * @param int    $first     Which number should be used for the first dupe increment
666
     */
667
    function increment_string(string $str, string $separator = '_', int $first = 1): string
668
    {
669
        preg_match('/(.+)' . preg_quote($separator, '/') . '([0-9]+)$/', $str, $match);
670

671
        return isset($match[2]) ? $match[1] . $separator . ((int) $match[2] + 1) : $str . $separator . $first;
672
    }
673
}
674

675
if (! function_exists('alternator')) {
676
    /**
677
     * Alternator
678
     *
679
     * Allows strings to be alternated. See docs...
680
     *
681
     * @param string ...$args (as many parameters as needed)
682
     */
683
    function alternator(...$args): string
684
    {
685
        static $i;
686

687
        if (func_num_args() === 0) {
688
            $i = 0;
689

690
            return '';
691
        }
692

693
        return $args[($i++ % count($args))];
694
    }
695
}
696

697
if (! function_exists('excerpt')) {
698
    /**
699
     * Excerpt.
700
     *
701
     * Allows to extract a piece of text surrounding a word or phrase.
702
     *
703
     * @param string $text     String to search the phrase
704
     * @param string $phrase   Phrase that will be searched for.
705
     * @param int    $radius   The amount of characters returned around the phrase.
706
     * @param string $ellipsis Ending that will be appended
707
     *
708
     * If no $phrase is passed, will generate an excerpt of $radius characters
709
     * from the beginning of $text.
710
     */
711
    function excerpt(string $text, ?string $phrase = null, int $radius = 100, string $ellipsis = '...'): string
712
    {
713
        if (isset($phrase)) {
714
            $phrasePos = stripos($text, $phrase);
715
            $phraseLen = strlen($phrase);
716
        } else {
717
            $phrasePos = $radius / 2;
718
            $phraseLen = 1;
719
        }
720

721
        $pre = explode(' ', substr($text, 0, $phrasePos));
722
        $pos = explode(' ', substr($text, $phrasePos + $phraseLen));
723

724
        $prev  = ' ';
725
        $post  = ' ';
726
        $count = 0;
727

728
        foreach (array_reverse($pre) as $e) {
729
            if ((strlen($e) + $count + 1) < $radius) {
730
                $prev = ' ' . $e . $prev;
731
            }
732
            $count = ++$count + strlen($e);
733
        }
734

735
        $count = 0;
736

737
        foreach ($pos as $s) {
738
            if ((strlen($s) + $count + 1) < $radius) {
739
                $post .= $s . ' ';
740
            }
741
            $count = ++$count + strlen($s);
742
        }
743

744
        $ellPre = $phrase ? $ellipsis : '';
745

746
        return str_replace('  ', ' ', $ellPre . $prev . $phrase . $post . $ellipsis);
747
    }
748
}
749

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.