Trimming String Left and Right

How can I trim 5 characters from a string left and right. eg.

4k2l3k4jc9l3kancie9

What you need to trim and save:

4k2l3      k4jc9l3ka     ncie9
  ^            ^           ^
remove        keep       remove
+3
source share
2 answers
$string = substr($string, 5, -5);
+7
source
$string = substr($string, 5, -5);//from left
$string = substr($string, 0, 5);//from right
+1
source

All Articles