I have a string 2010-2011, I would like to get result like this 2010-11, using php's substr() method I have tried but substr('2010'.'-'.'2011',0,7) not been able to get exact output, though I have tried from other posts.
3 Answers
Comments
You can use substr twice, first to get first five digits and second to get last two.
<?php
$string = "2010-2011";
echo substr($string, 0, 5) . substr($string, -2);
see example: https://eval.in/578870
((\d{2})\d{2})-\2(\d{2})might be useful, replace with\1-\3.