Jump to content

Archived

This topic is now archived and is closed to further replies.

All4172

How to search for partic article type (ie. php xml)

Recommended Posts

I have the following script that list the files in a dir (I use php 4 so can't use scandir).

[code]
<?php
if ($handle = opendir('/home/public_html/dir')) {
    echo "Directory handle";

    // List all the files
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
        echo "<P>";
    }

    closedir($handle);
}
?>
[/code]

How would I go about adding something saying, only display files that end in say .php or .xml ect?

Share this post


Link to post
Share on other sites
if(preg_match('/(\.php|\.xml)$/i',$file))
{
  //It is either PHP or XML.
}

To add more/less just add a pipe [b]|[/b], dot [b]\.[/b] and the extension, e.g: [b]\.html[/b]

Share this post


Link to post
Share on other sites

×

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.