Presto-X Posted November 18, 2009 Share Posted November 18, 2009 Hello everyone, I want to clean up image names after they have been uploaded, I only want to use [a-z] and [0-9] and turn spaces in to underscores? I was trying to use this but it took out the period before the image extension $image = strtolower(preg_replace("/^[a-z0-9][a-z0-9\-]+[a-z0-9]$/i", "", $image)); These are some of the other ways I have tride, I think I am close just not quite there yet: $targetChars = array(" ", "%20", "[", "]", "(", ")", "'", "-"); $image = str_replace($targetChars, "_", $image); $image = preg_replace('/^\W+|\W+$/', '', $image); $image = preg_replace('/\s+/', '_', $image); $image = strtolower(preg_replace('/\W-/', '', $image)); $image = preg_replace('/[^a-z0-9]/', '', $image); $image = strtolower(preg_replace("/^[a-z0-9][a-z0-9\-]+[a-z0-9]$/i", "", $image)); $image = preg_replace('/[^\w\d_ -]/si', '', $image); Link to comment https://forums.phpfreaks.com/topic/181959-clean-up-image-name-after-uploading/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.