Home >Backend Development >PHP Tutorial >mb_substr Let him click after he exceeds the word count

mb_substr Let him click after he exceeds the word count

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-09-13 09:00:211403browse

How to make him click more than the word limit?
The following is the illusion I wrote:

<code>mb_substr("1234567890",0,5,"utf-8");echo '...';
</code>

It will become 12345 at this time...no problem

But it will also display dots when it is not exceeded

<code>mb_substr("1234567890",0,15,"utf-8");echo '...';
</code>

1234567890...

The mb_substr function I checked online only introduces how to display the specified number of words
But I didn’t find how to set the conditions... it just clicks a little bit more than the number of displayed words I set

Reply content:

How to make him click more than the word limit?
The following is the illusion I wrote:

<code>mb_substr("1234567890",0,5,"utf-8");echo '...';
</code>

It will become 12345 at this time...no problem

But it will also display dots when it does not exceed

<code>mb_substr("1234567890",0,15,"utf-8");echo '...';
</code>

1234567890...

The mb_substr function I checked online only introduces how to display the specified number of words
But I didn’t find how to set the conditions... it just clicks a little bit more than the number of displayed words I set

You can only make your own judgment

<code>function my_substr($str, $start = 0, $length = 0, $encoding = 'utf-8')
{
    return (mb_strlen($str) >= ($length - $start)) ? (mb_substr($str, $start, $length, $encoding).'...') : $str;
}</code>
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