Laravel: function limit($value, $limit = 100, $end = '...') {if (mb_strwidth($value, 'UTF-8') <= $limit) {return $value;}return rtrim(mb_strimwidth($value,"/> Laravel: function limit($value, $limit = 100, $end = '...') {if (mb_strwidth($value, 'UTF-8') <= $limit) {return $value;}return rtrim(mb_strimwidth($value,">

Home >Backend Development >PHP Tutorial >Intercept string function

Intercept string function

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:50:481113browse

data-id="1190000005076800" data-license="cc">

Laravel:

<code>function limit($value, $limit = 100, $end = '...')
{
    if (mb_strwidth($value, 'UTF-8') <= $limit) {
        return $value;
    }

    return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
}
</code>

Ci:

<code>function word_limiter($str, $limit = 100, $end_char = '&#8230;')
{
    if (trim($str) === '')
    {
        return $str;
    }

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

    if (strlen($str) === strlen($matches[0]))
    {
        $end_char = '';
    }

    return rtrim($matches[0]).$end_char;
}
</code>

The above has introduced the interception string function, including the content of intercepting strings. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn