Welcome Guest, Not a member yet? Register   Sign In
Broke Code: ereg deprecated could anyone help?
#1

[eluser]Latavish[/eluser]
Hi Friends here at CI. I have an older program that I was working on that used php 4.1. Yes its outdated I know. lol I upgraded the program to php 5.3 but im now having an issue with this code.

I have read that ereg has now been deprecated in php, but does anyone now the replacement? or at a glance any one know what could fix this now broken code?

Code:
$path = $this->config->item('icons').$this->session->userdata('user_id');
                    $dir_handle = @opendir($path) or die("Unable to open folder");
                    
                    while (false !== ($file = readdir($dir_handle))) {
                    
                    if(ereg("(.*)\.(jpg|bmp|jpeg|png|gif)", $file)){
                    echo "<a href='/dashboard/selecticon/$file'><img src='$path/$file' alt='$file' width='100' height='100'></a> ";
                    }
                    
                    
                    }
                    closedir($dir_handle);

Thanks a million in advance.

Latavish
#2

[eluser]WanWizard[/eluser]
As the PHP manual suggests, replace ereg() by preg_match()

Code:
if(preg_match("/^(.*)\.(jpg|bmp|jpeg|png|gif)$/i", $file)){




Theme © iAndrew 2016 - Forum software by © MyBB