Friday, February 8, 2013

php get file list from location ends or start with some string preg_match

<?php 
$fontList = array();

$fontLocation = WWW_ROOT."img/brief/graphic/font_style";

if(file_exists($fontLocation) && is_dir($fontLocation)) {

    $dirs = array_diff( scandir( $fontLocation ), Array( ".", ".." ) );

    foreach($dirs as $fileName) {

        /* ENDS WITH .jpg */

        if(is_file($fontLocation."/".$fileName) && preg_match("/\.jpg$/i", $fileName)) {

            echo "MATCH: ".$fileName."<BR>";

        }

        /* STARTS WITH 'godhuli' */

        if(is_file($fontLocation."/".$fileName) && preg_match("/^godhuli/i", $fileName)) {

            echo "MATCH: ".$fileName."<BR>";

        }

    }

}

$list = array_filter($list, "__private_checkPregReplace54131256");

function __private_checkPregReplace54131256($input) {
    if(preg_match("/\./i", $input)) {
        return true;
    }
    return false;
}
?>

No comments:

Post a Comment