Basically, I have this code for reading directory contents: <? $mydir = "/path/to/dir/"; $d = dir($mydir); while($entry = $d->read()) { if ($entry!= "." && $entry!= "..") { echo "<br><a href=\"/dir/",$entry,"\">$entry</a>"; } } $d->close(); ?> Code (markup): It reads the contents of the specified directory ($mydir) and prints a load of links to each of the files within that directory on the page it's placed on. My problem: As all filenames obviously have an extension, the link's anchor text ($entry) is appearing as the full filename like "mypage.php". How can I adapt the code to remove the file extention for the anchor text? Thanks in advance for any pointers and/or solutions.
echo '<br><a href="/dir/'. $entry .'">'. preg_replace('/\.[a-z0-9]+$/i', null, $entry) .'</a>; PHP: Untested but should work.
Thanks Nico, that particularly line came back with a syntax unexpected $end error. I changed it to the following and it now works superbly: echo "<br><a href=\"/dir/". $entry ."\">". preg_replace('/\.[a-z0-9]+$/i', null, $entry) ."</a>"; Code (markup): Thanks for the help, wouldn't have got anywhere near it without you.