Private Label and Cobranded VoIP Solutions
BrainCast internet & phone based message/memo recording & reminder organization system
Internet Phone Service and Broadband Phone Service by ViaTalk

Go Back   VoIP Forums, Internet Phone Service Forums, & Web Hosting Forums > CoderForums - Programming Discussion > General Programming Issues > Programming Languages & Technologies > PHP

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-18-2002, 06:21 AM
Gizmo's Avatar
Gizmo Gizmo is offline
Well on the way
 
Join Date: Dec 2001
Posts: 46
Warning! PHP query

Hello
I have got a simple bit of code to list all the files in a directory (see below) and I was wondering a couple of things. The files in the directory are created by another programme and are labelled "feb05.htm" "jan06.htm" "aug15.htm" etc.:

1) The script sorts these alphabetically. How can I sort them so they are in calendar order? I.e. Jan then Feb etc.

2) How can I get rid of the .htm extension when the files are listed? I.e. just Jan06 etc.

3) When the list is produced, is it possible to change Jan06 to say January06 (by splitting the Jan and the 06 into two and then altering the Jan using an IF statement) or am I just being absurd?

PHP Code:
<?
$p 
"results";
$d opendir($p);

$f readdir($d);

  while(
$f !== false)

  if(
$f <> "." and $f <> ".." and $f <> "index.htm") {echo("&nbsp;&nbsp;<a href=results/$f>$f</a>&nbsp;&nbsp;");};
  
$f readdir($d) ;
closedir($d);
?>
any help would be greatly appreciated

Ross
__________________
"Practice makes perfect, but no-one can be perfect so why bother?"
Reply With Quote
  #2  
Old 02-18-2002, 11:48 PM
toosweet4u toosweet4u is offline
Registered User
 
Join Date: Jul 2001
Location: Houston, Texas
Posts: 4
Send a message via ICQ to toosweet4u Send a message via AIM to toosweet4u Send a message via Yahoo to toosweet4u
I don't know about the calendar order stuff, but you can get rid of the .htm extension using the explode function.

PHP Code:
<?
explode
(".htm"$f);
?>
__________________
g-e.org
Reply With Quote
  #3  
Old 02-19-2002, 01:52 AM
Gizmo's Avatar
Gizmo Gizmo is offline
Well on the way
 
Join Date: Dec 2001
Posts: 46
Thanks for the help toosweet4u
Where would I put that in the above code though?

cheers
__________________
"Practice makes perfect, but no-one can be perfect so why bother?"
Reply With Quote
  #4  
Old 02-26-2002, 11:46 PM
Gizmo's Avatar
Gizmo Gizmo is offline
Well on the way
 
Join Date: Dec 2001
Posts: 46
Hi again,

Could someone possibly have a look at:

HKCC Bridge Results

It's the table down the bottom that is giving me grief.

1) There are 3 blank cells. These are the ".", "..", and something else (directory listings) from the above code. I thought it would ignore them, but instead it creates a blank cell for each. Can I get rid of these???

2) How would I get rid of the .htm ? toosweet mentioned it, but I can't see how to fit that in to what I have already

3) Is there any way to order the files that are displayed? e.g. jan, then feb etc.

4) Is there (probably...) a better way of doing all this?

Sorry for the load. It's a really simple process that I just can't seem to grasp.
thanks for any help

Ross
__________________
"Practice makes perfect, but no-one can be perfect so why bother?"
Reply With Quote
  #5  
Old 02-27-2002, 11:49 AM
top5mov top5mov is offline
Senior Customer
 
Join Date: Jun 2001
Location: Pittsburgh
Posts: 266
start with this much, give it a try. it should do all the string replacements you asked for. sorting by date is more difficult, i'll have to work on that for a bit.

PHP Code:
<?php
$p 
"results";
$d opendir($p);

$f readdir($d);

while(
$f !== false)
{
  if(
$f != "." and $f != ".." and $f != "index.htm"
  {
    
$prettyname $f;
    
eregi_replace(".htm"""$prettyname);
    
eregi_replace("jan""January "$prettyname);
    
eregi_replace("feb""February "$prettyname);
    
eregi_replace("mar""March "$prettyname);
    
eregi_replace("apr""April "$prettyname);
    
eregi_replace("may""May "$prettyname);
    
eregi_replace("jun""June "$prettyname);
    
eregi_replace("jul""July "$prettyname);
    
eregi_replace("aug""August "$prettyname);
    
eregi_replace("sep""September "$prettyname);
    
eregi_replace("oct""October "$prettyname);
    
eregi_replace("nov""November "$prettyname);
    
eregi_replace("dec""December "$prettyname);
    echo(
"&nbsp;&nbsp;<a href='results/$f'>$prettyname</a>&nbsp;&nbsp;");
  }
  
  
$f readdir($d) ;
}

closedir($d);
?>
Reply With Quote
  #6  
Old 02-27-2002, 08:54 PM
Gizmo's Avatar
Gizmo Gizmo is offline
Well on the way
 
Join Date: Dec 2001
Posts: 46
Thanks top5mov, I will give it a try tonight. I THINK I may have solved the blank cell problem, so that just leaves the ordering by date. I thought the server would order them for me (i.e. by the date the file was uploaded), but no such luck
__________________
"Practice makes perfect, but no-one can be perfect so why bother?"
Reply With Quote
  #7  
Old 02-28-2002, 06:43 AM
Gizmo's Avatar
Gizmo Gizmo is offline
Well on the way
 
Join Date: Dec 2001
Posts: 46
no luck top5mov... it just displayed it the same as usual

http://hkccbridge.rossharding.com/indextrial.php

is it anything to do with the fact that it cannot find, say, 'jan' as it is 'jan' with '28' attached onto the end?
NOPE, it's not that, just tried with 'jan.html' and still the same...

any ideas? thanks again for the help

I got rid of the extra cells though...
__________________
"Practice makes perfect, but no-one can be perfect so why bother?"
Reply With Quote
  #8  
Old 03-12-2002, 07:56 AM
Gizmo's Avatar
Gizmo Gizmo is offline
Well on the way
 
Join Date: Dec 2001
Posts: 46
Unfortunately, the code mentioned by top5mov didn't work for me somehow. If anyone is curious, I ended up doing the following:

PHP Code:
$p "results";
$d opendir($p);

$f readdir($d);

  while(
$f !== false)
    {
      
$prettyname $f;

  
$ending eregi_replace(".htm"""$prettyname);

  if(
$f != "." and $f != ".." and $f != "index.htm") {

  echo(
"<td bgColor=white valign='center' align='center'>"); echo("&nbsp;&nbsp;<a href=results/$f>$ending</a>&nbsp;&nbsp;");};
  
$f readdir($d) ;
  

           }
     
 
closedir($d); 
i.e. I only did 1 of the two things. I settled for removing the .htm instead of renaming jan etc. to January etc. And even then I only managed to do it by assigning the eregi_replace to a variable ($ending). Don't know why...

I also tried:

PHP Code:
$p "results";
$d opendir($p);

$f readdir($d);


  while(
$f !== false)
    {
  if(
$col ==1) {
  echo(
"<tr>");
  }
    
$prettyname $f;
  
$start eregi_replace("jan""January "$prettyname); }
  
$start eregi_replace("feb""February "$prettyname);
  
$start eregi_replace("mar""March "$prettyname);
  
$start eregi_replace("apr""April "$prettyname);
  
$start eregi_replace("may""May "$prettyname);
  
$start eregi_replace("jun""June "$prettyname);
  
$start eregi_replace("jul""July "$prettyname);
  
$start eregi_replace("aug""August "$prettyname);
  
$start eregi_replace("sep""September "$prettyname);
  
$start eregi_replace("oct""October "$prettyname);
  
$start eregi_replace("dec""December "$prettyname);
  
  
$ending eregi_replace(".htm"""$prettyname);


 if(
$f != "." and $f != ".." and $f != "index.htm") {

  echo(
"<td bgColor=white valign='center' align='center'>"); echo("&nbsp;&nbsp;<a href=results/$f>$start$ending</a>&nbsp;&nbsp;");};
  
$f readdir($d) ;
 
       
      }
    
 
closedir($d); 
using $start and $ending to try and display both parts, but this only displayed EVERYTHING as "February" for some reason. No .htm , no number... weird
__________________
"Practice makes perfect, but no-one can be perfect so why bother?"
Reply With Quote
  #9  
Old 03-12-2002, 09:04 AM
top5mov top5mov is offline
Senior Customer
 
Join Date: Jun 2001
Location: Pittsburgh
Posts: 266
you're right, i forgot to assign the results of the eregi_replace back to the string, so it was just being thrown away each time.

put "$prettyname = " before all the eregi_replace lines and it should be fine. you almost had it right with the second snippet you posted, but the reason it didn't work is because you've got a stray "}". look:

PHP Code:
  while($f !== false)
    {
  if(
$col ==1) {
  echo(
"<tr>");
  }
    
$prettyname $f;
  
$start eregi_replace("jan""January "$prettyname); }
  
$start eregi_replace("feb""February "$prettyname);
  ... 
...so your while loop is ending right after the replacement for january. you really need to write your code with strict rules of proper indentation to help you catch errors like that. perhaps you did so originally and it just didn't carry over into the forums.

anyways, here's what it should look like:

PHP Code:
<?php
$p 
"results";
$d opendir($p);

$f readdir($d);

while(
$f !== false)
{
  if(
$f != "." and $f != ".." and $f != "index.htm"
  {
    
$prettyname $f;
    
$prettyname eregi_replace(".htm"""$prettyname);
    
$prettyname eregi_replace("jan""January "$prettyname);
    
$prettyname eregi_replace("feb""February "$prettyname);
    
$prettyname eregi_replace("mar""March "$prettyname);
    
$prettyname eregi_replace("apr""April "$prettyname);
    
$prettyname eregi_replace("may""May "$prettyname);
    
$prettyname eregi_replace("jun""June "$prettyname);
    
$prettyname eregi_replace("jul""July "$prettyname);
    
$prettyname eregi_replace("aug""August "$prettyname);
    
$prettyname eregi_replace("sep""September "$prettyname);
    
$prettyname eregi_replace("oct""October "$prettyname);
    
$prettyname eregi_replace("nov""November "$prettyname);
    
$prettyname eregi_replace("dec""December "$prettyname);

    echo(
"&nbsp;&nbsp;<a href='$p/$f'>$prettyname</a>&nbsp;&nbsp;");
  }
  
  
$f readdir($d) ;
}

closedir($d);
?>
Reply With Quote
  #10  
Old 03-12-2002, 09:39 AM
Gizmo's Avatar
Gizmo Gizmo is offline
Well on the way
 
Join Date: Dec 2001
Posts: 46
Brilliant!

Thanks top5mov. You are right about the layout of the code. I have a habit of beig a bit sloppy and just wanting to get it done quickly. Did not pick up on the '{'

Now I've just got to figure out how to put it all in a table, as I originally had it.
Should be OK though, if I get my 'order' the right way round

Thanks again!
__________________
"Practice makes perfect, but no-one can be perfect so why bother?"
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump