DapperDanMan Posted June 4, 2006 Share Posted June 4, 2006 I have the following code to change a filename when I am creating a thumbnail on upload:[code]$file = "something.jpg";$tb_image = explode(".", $file);$array = array($tb_image[0], 'tb.jpg');$together = implode("_", $array);[/code]I am curious, is there a better way than exploding the name to insert the "_tb" into the middle of the name?DDM Quote Link to comment https://forums.phpfreaks.com/topic/11134-changing-a-filename/ Share on other sites More sharing options...
Buyocat Posted June 4, 2006 Share Posted June 4, 2006 Use eregi_replace.ex[code]$file = thumb.jpg$thumbnail = eregi_replace ('.jpg', '_tb.jpg', $file);[/code]you can read more about eregi_replace here:[a href=\"http://us2.php.net/eregi_replace\" target=\"_blank\"]http://us2.php.net/eregi_replace[/a] Quote Link to comment https://forums.phpfreaks.com/topic/11134-changing-a-filename/#findComment-41631 Share on other sites More sharing options...
DapperDanMan Posted June 4, 2006 Author Share Posted June 4, 2006 Awesome!I knew there had to be a better, cleaner way of writing this out. Thank you very much.DDM Quote Link to comment https://forums.phpfreaks.com/topic/11134-changing-a-filename/#findComment-41636 Share on other sites More sharing options...
DapperDanMan Posted June 4, 2006 Author Share Posted June 4, 2006 Awesome!I knew there had to be a better, cleaner way of writing this out. Thank you very much.DDM Quote Link to comment https://forums.phpfreaks.com/topic/11134-changing-a-filename/#findComment-41646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.