Jump to content

Parse and rebuild array value


SaranacLake

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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;
}
	

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.