-1

I have a code which read file inside a directory. But I am using ereg(), Now I am getting a deprecated error on PHP 5.3.

After search on google, someone said to replace ereg() with perg_match().

But after replacing with perg_math() I am getting an error:

preg_match(): No ending delimiter '.' found

I am not a PHP expert kndly fix this problem.

$path = THEME_DIR.'/'.$path;
foreach(array_diff(scandir($path), array('.', '..')) as $f) 
    if (is_file($path . '/' . $f) && (('.php') ? ereg('.php' . '$' , $f) : 1)) 
        $l[] = $f;
return $l; 
user007
  • 3,203
  • 13
  • 46
  • 77
  • 2
    Did you read the entry for preg_match() on the manual? – Damien Pirsy Sep 16 '13 at 05:14
  • Yes, but did not understand that – user007 Sep 16 '13 at 05:15
  • 1
    You need to add delimiters to your regex when using `preg_match`. http://php.net/manual/en/regexp.reference.delimiters.php – elclanrs Sep 16 '13 at 05:16
  • _I am not a PHP expert kndly fix this problem._ RTFM – NullPoiиteя Sep 16 '13 at 05:23
  • 1
    Try to read this: [Switching from PHP !ereg and !eregi to preg_match](http://stackoverflow.com/questions/6465601/switching-from-php-ereg-and-eregi-to-preg-match) or this [How can I convert ereg expressions to preg in PHP?](http://stackoverflow.com/questions/6270004/how-can-i-convert-ereg-expressions-to-preg-in-php) – teo Sep 16 '13 at 05:26

1 Answers1

2

preg_match regex should be inside the delimeters.. "/your regex here/".. the deprecated POSIX regex were the one which did not require any delimeter.. eg ereg(")

so just change your regex to

"/old regex/"

PHP regular expressions: No ending delimiter '^' found in for reference

$path = THEME_DIR.'/'.$path;
foreach(array_diff(scandir($path), array('.', '..')) as $f) 
    if (is_file($path . '/' . $f) && (('.php') ? ereg('/.php' . '$/' , $f) : 1)) 
        $l[] = $f;
return $l; 
Community
  • 1
  • 1
Nishant
  • 3,614
  • 1
  • 20
  • 26