Icebergness Posted November 18, 2011 Share Posted November 18, 2011 Hi, I currently produce a directory listing which simply shows the name of the file as a link. The code for this is below: <?php $link = "dol_2011\_feb"; if (file_exists($link)) echo "<h2>February</h2>"; { if ($handle = opendir($link)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(!preg_match("/\.pdf$/", $file)) continue; { echo "<a href=\"".$link."/".$file."\">".substr_replace($file ,"",-4)."</a><br>";} } } echo "<br>"; closedir($handle); } } ?> This works perfectly, although the files in the folder are all named "DOLddmmyy.pdf" (obviously ddmmyy is the current date). The current script removes the ".pdf", but I would like to be able to format the text like dd/mm/yy. Is it possible to apply all these changes on the same string? Renaming the files isn't possible I'm afraid, so I'm stuck with the current file names. Many thanks Link to comment https://forums.phpfreaks.com/topic/251376-substr_replace-query/ Share on other sites More sharing options...
QuickOldCar Posted November 18, 2011 Share Posted November 18, 2011 easiest way I could come up with <?php $string = "DOLddmmyy.pdf"; $string_day = substr($string, 3, 2); $string_month = substr($string, 5, 2); $string_year = substr($string, 7, 2); $combine_strings = "$string_day/$string_month/$string_year"; echo $combine_strings; ?> Link to comment https://forums.phpfreaks.com/topic/251376-substr_replace-query/#findComment-1289311 Share on other sites More sharing options...
Icebergness Posted November 18, 2011 Author Share Posted November 18, 2011 Hi QuickOldCar, This worked perfectly, thank you very much Link to comment https://forums.phpfreaks.com/topic/251376-substr_replace-query/#findComment-1289323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.