Yet another php ereg fix

Posted by casben79 on Stack Overflow See other posts from Stack Overflow or by casben79
Published on 2010-05-31T05:35:02Z Indexed on 2010/05/31 5:42 UTC
Read the original article Hit count: 320

Filed under:
|
|

I have a small chunk of coding I need to take from ereg to preg_match. Here is the code.

function be_file_list($d, $x) {
    foreach (array_diff(scandir($d), array('.', '..')) as $f) {
        if (is_file($d . '/' . $f) && (($x) ? ereg($x.'$',$f) : 1)) {
            $l[] = $f;
        }
    }

    return $l;
}

This code works as expected even if it doesn't look too pretty (source: http://www.php.net/manual/en/function.scandir.php)

but as ereg is deprecated, I would really like to make it preg_match, or something like that.

I have been messing with this all afternoon and the PC is about to go out the window. I would have thought that

preg_match("/"$x.'$',$f"/")

would have worked but no dice.

Any help would be great.

Cheers Ben

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-match