Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim string from left and from right

Tags:

php

trim

How can I trim 5 characters from a string from left and right side. e.g.

4k2l3k4jc9l3kancie9

What should be trimmed and kept are:

4k2l3      k4jc9l3ka     ncie9
  ^            ^           ^
remove        keep       remove
like image 471
MacMac Avatar asked Feb 16 '26 07:02

MacMac


1 Answers

$string = substr($string, 5, -5);
like image 171
Emil Vikström Avatar answered Feb 18 '26 20:02

Emil Vikström



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!