Skip to content
Advertisement

Removing a .jpg extension from a string in php

I have the following code for a gallery. When the thumbnail is clicked, I would like to open the big image in another window (which it does) and then be able to navigate to the next image in the new window, but in order to do this, I need to strip the .jpg off the filenames so that I can just ‘+1’ to the filename, as they are sequentially numbered.

For example, files are numbered 001.jpg, 002.jpg, 003.jpg etc.

I currently have:

JavaScript

Which give the name of the file with .jpg extension, for example basename=001.jpg.

Then I have :

JavaScript

but the output I expect, 001, doesn’t echo. It just has nothing… img=

JavaScript

What am I doing wrong? Can anyone point me in the right direction?

Many thanks, Kirsty

Advertisement

Answer

Try this

JavaScript

result will be

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement