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!

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);
}

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

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.