Moron Posted June 28, 2007 Share Posted June 28, 2007 Okay, I finally have the code I need, BUT.... I need to do one thing: truncate the ".txt" off of filenames in the display list. My code is: <?php echo "<center>"; echo "<font size=\"5\" color=\"#000000\" face=\"times new roman\"><b>Page Title</b></font>"; echo "</center>"; echo "<center>"; echo "<font size=\"8\" color=\"#000000\" face=\"times new roman\"><b>Bid Requests</b></font>"; echo "</center>"; $file = basename($path); $path = './bidfolder/'; $handle = opendir($path); while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $filemtime = filemtime($path . $file); $file_array[$file] = $filemtime; } } $path_parts = pathinfo('/www/htdocs/index.html'); asort($file_array); echo "<BR><BR>"; foreach ($file_array as $key => $value) { echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))); echo "<center>"; echo "<font size=\"3\" color=\"#000000\" face=\"arial\">"; echo $key . '<br><br>'; readfile($path . $key); echo "<BR><BR>"; echo "<img src='http://www.website.org/images/bidbar.jpg'>"; echo "<BR>"; echo "<BR>"; echo "</font>"; echo "</center>"; } ?> What this is doing is... 1. Displays the filenames from a folder called "bidfolder." 2. Displays the contents of each file below the filename. The "preg_replace" is no longer working for this. Is it just in the wrong place, or would I be better off using pathinfo or basename? This part will totally complete my project and any help is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))); if that is the prob give as the $file value of that say the echoed $file then we will make the pattern Quote Link to comment Share on other sites More sharing options...
btherl Posted June 29, 2007 Share Posted June 29, 2007 "The "preg_replace" is no longer working for this." Can you elaborate on this? How isn't it working? Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 '/\..*$/' that will match $ means end of the srting * means 0 or more \ means escape the dot . sample sample..anything here and that regular expression will work for file name like sample.php ,.txt etc Quote Link to comment Share on other sites More sharing options...
Moron Posted June 29, 2007 Author Share Posted June 29, 2007 "The "preg_replace" is no longer working for this." Can you elaborate on this? How isn't it working? It did what I wanted in the other codeset; it removed the ".txt" from the filenames. Do I just have it in the wrong place now or is there something else I'm missing? Quote Link to comment Share on other sites More sharing options...
Moron Posted June 29, 2007 Author Share Posted June 29, 2007 Bump. I seem to have the "preg_replace" in the wrong spot. I guess that's what I'm really saying. Can someone show me exactly where it should go? Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.