0

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
if ($handle = opendir('poems/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n <br />";
        }
    }
    closedir($handle);
}
?>

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

Thanks!

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by ShawnCplus
0

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
if ($handle = opendir('poems/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n <br />";
        }
    }
    closedir($handle);
}
?>

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
if ($handle = opendir('poems/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && $file[0] == 'A') {
            echo "$file\n <br />";
        }
    }
    closedir($handle);
}

Edited by ShawnCplus: n/a

0

Thanks for the quick reply ShawnCplus. It spares me an awful lot of pain and hair ripping! Thank you so much!

0

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)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.