www.webdeveloper.com
Results 1 to 2 of 2

Thread: Use of preg_match instead ereg

  1. #1
    Join Date
    Sep 2004
    Location
    Sri Lanka
    Posts
    473

    Question Use of preg_match instead ereg

    Hi,

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

    PHP Code:
    function 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

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

    Code:
    [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
    Location
    Ankh-Morpork
    Posts
    19,633
    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
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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



Recent Articles