4

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
  • 44,700
  • 8
  • 66
  • 79

3 Answers3

11

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
  • 942
  • 10
  • 22
1

Please read the manual substr.

$str = substr($str, -4);
Ben
  • 4,856
  • 4
  • 17
  • 26
0

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

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

pardeep
  • 331
  • 1
  • 5
  • 6