7

I have this string in my database like 12-12-2067. I want to only display the last 4 words in the string 2067 in my view. How do i achieve this ?

$get_string = Item::all()->first();


<p>{{get_string}}</p>
lagbox
  • 48,571
  • 8
  • 72
  • 83

3 Answers3

14

You can use:

substr ($getstring->string, -4)

Because of (-) it will start form the end of the string and it will take the next 4 characters.

Take care that first() it will return an object and not the string you want.

Radu
  • 995
  • 12
  • 23
2

Please read the manual substr.

$str = substr($str, -4);
Ben
  • 5,069
  • 4
  • 18
  • 26
0

string substr ( string $string , int $start [, int $length ] )

$dynamicstring = "12-07-2017"; $newstring = substr($dynamicstring, -4);

pardeep
  • 359
  • 1
  • 5
  • 7