I collect the files from a folder using some Smarty code:
{assign var=files value="uploads/Documenten/GPS-Tracks/*.html"|glob}
{if count($files)}
<ul>
{foreach from=$files item='file'}
{assign var='gpstrack_location' value="{$file|cms_escape:'urlpathinfo'}"}
{if !$file|contains:"index"}
<li><a href="{$file}">{$file|basename|substr:0:-5}</a></li>
{/if}
{/foreach}
</ul>
{/if}
This gives me a sorted list basedon the first character.
- Brighton-Gosport_2108
- Brighton-Littlehampton_2012
- Brighton-Portmouth-Brighton_2018
- Bruinisse-Herkingen_2012
- BurnhamonCrouch_Vlissingen_22aug13
- Calais-Dieppe_2014
- Carteret-Dielette_2012
- Cherbourg-StVaast_2012
- Clubwedstrijd_17sept11
- Clubwedstrijd_18sep10
- Clubwedstrijd_21sep13
- Cowes-BeauLieu_River_2012
- Dartmouth-Guernsey_2012
- Deauville-Honfleur_2012
- Denemarken_2008
- Dielette-Alderney_2012
- Dieppe-Boulogne_2012
What I'd like to achive is a sorted list based on the last two charaters. Is there in Smarty or PHP a way to do this?
Thanks in advance for your help!
UPDATE: I got myself a couple of steps futher :) There remains one warning I'm not able to solve: The code so far:
<?php
$folder = '<some foldername>';
$files = array_values(preg_grep('/^([^.])/', scandir($folder, SCANDIR_SORT_ASCENDING)));
//$files = scandir($folder);
//print_r($files);
usort(var_dump($files, function ($a, $b){
if ($a || $b <> "")
return substr($b, strlen($b) - 2) - substr($a, strlen($a) - 2);
}));
?>
The warning I get, and thought to solve with the 'or'-statement:
[
- 121] => string(29) "Weymouth-Lyme_Reges_2012.html"
- [122]=> string(24) "Yarmouth-Poole_2012.html" }
- object(Closure)#1036 (1) {["parameter"]=> array(2) { ["$a"]=> string(10) "" ["$b"]=> string(10) "" } } Warning: usort() expects exactly 2 parameters, 1 given in /Users/name/Sites/install/assets/udt/sort-on-last-characters.php on line 55
Someone able to get me a step further?