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

WBOY
Release: 2016-09-13 09:00:21
Original
1371 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template