CodeIgniter Forums
Broke Code: ereg deprecated could anyone help? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Broke Code: ereg deprecated could anyone help? (/showthread.php?tid=32781)



Broke Code: ereg deprecated could anyone help? - El Forum - 08-04-2010

[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


Broke Code: ereg deprecated could anyone help? - El Forum - 08-04-2010

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

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