Smarty: replace middle part of string
<p>Hello I have a smarty variable which has values like (Number, Number, Number) and I would like to replace the middle part:</p>

<ul>
<li>2, 3, 4, 5, 6 -> 2-6</li>
<li>1, 2, 3, 4 -> 1-4</li>
<li>7, 8, 9, 10, 11 -> 7-11</li>
</ul>

<p>So basicaly I want to first and the last number to be combined by a "-" the rest should be removed. How can I achieve this in smarty?</p>

<p>Thanks in advance!</p>