944,062 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 466
  • PHP RSS
Oct 22nd, 2009
0

Display all files in directory beginning with A

Expand Post »
Hi all,

I've tried searching both here and google for help on this one. I'm not quite sure what to call it basically I have a directory with different files all .txt. I want to display only the ones beginning with letter A. How do I modify my below code to do this?

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if ($handle = opendir('poems/')) {
  3. while (false !== ($file = readdir($handle))) {
  4. if ($file != "." && $file != "..") {
  5. echo "$file\n <br />";
  6. }
  7. }
  8. closedir($handle);
  9. }
  10. ?>

I know I need to use something like A* but I don't even know what to call it to search for it?

Thanks!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
peck3277 is offline Offline
60 posts
since Jul 2009
Oct 22nd, 2009
0
Re: Display all files in directory beginning with A
Click to Expand / Collapse  Quote originally posted by peck3277 ...
Hi all,

I've tried searching both here and google for help on this one. I'm not quite sure what to call it basically I have a directory with different files all .txt. I want to display only the ones beginning with letter A. How do I modify my below code to do this?

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if ($handle = opendir('poems/')) {
  3. while (false !== ($file = readdir($handle))) {
  4. if ($file != "." && $file != "..") {
  5. echo "$file\n <br />";
  6. }
  7. }
  8. closedir($handle);
  9. }
  10. ?>

I know I need to use something like A* but I don't even know what to call it to search for it?

Thanks!

php Syntax (Toggle Plain Text)
  1. <?php
  2. if ($handle = opendir('poems/')) {
  3. while (false !== ($file = readdir($handle))) {
  4. if ($file != "." && $file != ".." && $file[0] == 'A') {
  5. echo "$file\n <br />";
  6. }
  7. }
  8. closedir($handle);
  9. }
Last edited by ShawnCplus; Oct 22nd, 2009 at 11:24 am.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Oct 22nd, 2009
0
Re: Display all files in directory beginning with A
Thanks for the quick reply ShawnCplus. It spares me an awful lot of pain and hair ripping! Thank you so much!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
peck3277 is offline Offline
60 posts
since Jul 2009
Oct 22nd, 2009
0
Re: Display all files in directory beginning with A
Click to Expand / Collapse  Quote originally posted by peck3277 ...
Thanks for the quick reply ShawnCplus. It spares me an awful lot of pain and hair ripping! Thank you so much!
As a short explanation strings are arrays of characters so if you want to get the 3rd letter in a string just do $string[2] (counting begines at 0)
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Hi Please help me on PHP mail Looking for a process which sends email
Next Thread in PHP Forum Timeline: PHP Parse Error: parse error in errormsg.php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC