Jump to content


Photo

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


  • Please log in to reply
1 reply to this topic

#1 All4172

All4172
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 10 July 2006 - 09:16 PM

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

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

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

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 10 July 2006 - 09:24 PM

if(preg_match('/(\.php|\.xml)$/i',$file))
{
  //It is either PHP or XML.
}

To add more/less just add a pipe |, dot \. and the extension, e.g: \.html
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users