Results 1 to 2 of 2

Thread: Use of preg_match instead ereg

  1. #1
    Join Date
    Sep 2004
    Sri Lanka

    Question Use of preg_match instead ereg


    I have the following function for listing files in a directory with given extenstion/file type.

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

    Earlier it worked fine however now I see an error in error logs - given below.

    [15-Nov-2013 11:35:00 America/New_York] PHP Deprecated:  Function ereg() is deprecated in /home/****/public_html/****/API/***.php on line 21
    Can someone please let me know a solution for this, I tried with preg_match but it didnt help me.

    It seems I have put a different regex which I do not understand.

    Your help is highly appreciated.

    Thanking you

  2. #2
    Join Date
    Aug 2004
    Well, if the objective is to allow some wildcards when getting a directory listing, I'd probably just switch to using glob() instead of scandir(). Otherwise, I think you could just add delimiters around the pattern and use it in preg_match():
    PHP Code:
    preg_match("#$x#" '$' $f
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center