note 47066 deleted from function.preg-replace by tularis

From: Date: Sun, 18 Jun 2006 13:21:51 +0000
Subject: note 47066 deleted from function.preg-replace by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114302@lists.php.net to get a copy of this message
Note Submitter: zobier(at)hotmail(dot)com ---- If you want to avoid filename conflicts, for example when handling uploaded files, this regex will append a digit before the extension or increment an existing one. e.g. my_file.ext >> my_file_1.ext my_file1.ext >> my_file_2.ext <?php while ( file_exists ( "$uploaddir/$file_name" )) { $file_name = preg_replace ( "/^(.+?)(_?)(\d*)(\.[^.]+)?$/e", "'\$1_'.(\$3+1).'\$4'", $file_name ); } ?>

« previous php.notes (#114302) next »