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>
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>
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.
string substr ( string $string , int $start [, int $length ] )
$dynamicstring = "12-07-2017"; $newstring = substr($dynamicstring, -4);