SaranacLake Posted December 6, 2019 Share Posted December 6, 2019 Hello. I have a simple array with a key/value pair like this... foreach($photoFiles as $photoKey => $photoValue){ } The $photoValue would be the file-name (e.g. "IMG_2340.JPG") and is used in my photo-gallery. Now I am building a photo-details page and what I would like to do is have that larger image be "IMG_2340_large.JPG" Is it possible to split up the array value, insert "_large" and then re-assemble the $photoValue so I can use it here... <a href='client1/galleries/$galleryID/{$photoValue}'><image here</a> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/ Share on other sites More sharing options...
SaranacLake Posted December 6, 2019 Author Share Posted December 6, 2019 How about this... foreach($photoFiles as $photoKey => $photoValue){ $new = str_replace(".", "_large.", $photoValue); } Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572267 Share on other sites More sharing options...
requinix Posted December 6, 2019 Share Posted December 6, 2019 As long as your files only ever have the one period in their names, I guess. Otherwise I would tell you to get the name without the extension, add your suffix, and then add the extension. pathinfo() would help with that. Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572269 Share on other sites More sharing options...
SaranacLake Posted December 6, 2019 Author Share Posted December 6, 2019 1 minute ago, requinix said: As long as your files only ever have the one period in their names, I guess. Otherwise I would tell you to get the name without the extension, add your suffix, and then add the extension. pathinfo() would help with that. Can I use pathinfo() just on a filename and not a path? Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572270 Share on other sites More sharing options...
requinix Posted December 6, 2019 Share Posted December 6, 2019 Still the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572271 Share on other sites More sharing options...
SaranacLake Posted December 6, 2019 Author Share Posted December 6, 2019 13 minutes ago, requinix said: Still the same thing. 23 minutes ago, SaranacLake said: How about this... foreach($photoFiles as $photoKey => $photoValue){ $fileNameArray = pathinfo($photoValue); $photoName = $fileNameArray['filename']; $photoExt = $fileNameArray['extension']; $newname = $photoName . "_med." . $photoExt; } Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572272 Share on other sites More sharing options...
requinix Posted December 6, 2019 Share Posted December 6, 2019 I don't know, you tell me. Does it work? Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572275 Share on other sites More sharing options...
SaranacLake Posted December 6, 2019 Author Share Posted December 6, 2019 3 minutes ago, requinix said: I don't know, you tell me. Does it work? It works Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572276 Share on other sites More sharing options...
requinix Posted December 6, 2019 Share Posted December 6, 2019 Good. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309640-parse-and-rebuild-array-value/#findComment-1572277 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.