Jump to content

Coding help, PLEASE?


Moron

Recommended Posts

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.

 

 

Link to comment
Share on other sites

'/\..*$/' 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

 

 

Link to comment
Share on other sites

"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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.