Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ibe's avatar
Level 1

How to get last characters of string

Hi there, I don't how I can get the last characters of my string.

What I am making is a read more button, in the first part it gets the characters from 0 to 100 (works fine), but then in the second part I want all the characters from 100 till the end of the string... Does someone know how to please?

 <span>{{substr($calendar->details, 0, 100)}}{{ strlen($calendar->details) > 100 ? "..." : ""}} </span>
  <div>
    <span id="text">
      here all the text after 100 charachters
    </span>
  </div>
  <div class="btn-container">
    <button id="toggle">Read More</button>
  </div>

Thanks!

0 likes
7 replies
Cronix's avatar

Laravel has a nice helper to do that:

<span>{{ str_limit($calendar->details, 100, '...') }}</span>

https://laravel.com/docs/5.6/helpers#method-str-limit

And you can do this for the other part:

@if (strlen($calendar->details) > 100)
    <span id="text">
          ...{{ substr($calendar->details, 100) }}
    </span>
@endif

1 like
click's avatar

For your first part there is a handy laravel helper:

str_limit($calendar->details, 100);

But to show everything after the first 100 there is no easy helper but you could create your own helper for that that contains:

mb_substr($calendar->details, 100)
2 likes
Joucke's avatar

Well, if substr(0,100) gets the fitst 100, and you already calculate strlen, won't substr(100, strlen) or something like that get the remainder?

1 like
tykus's avatar
tykus
Best Answer
Level 104

For the beginning:

str_limit($calendar->details, 100);

For the end:

substr($calendar->details, 100)
2 likes
Cronix's avatar

Sure thing. Mine just had an additional check to not even show the span with the remainder of the text unless it was > 100.

Please or to participate in this conversation.