Biker John
Biker John

Reputation: 2711

Remove .jpg extension from path

What is the less expensive solution to remove ".jpg" extension from path, for example

lib/img/img.jpg  > lib/img/img

I will use it in loop 6 times, thats why i need a lightweight solution.

Upvotes: 0

Views: 122

Answers (2)

Niels Keurentjes
Niels Keurentjes

Reputation: 41958

Honestly, six isn't much. Start optimizing when you have a loop that runs a thousand times at least.

Having said that, you're looking for pathinfo function.

Upvotes: 1

Cody Caughlan
Cody Caughlan

Reputation: 32748

The pathinfo native method is probably your best bet. The output is an array with components that you can then piece back together:

$parts = pathinfo("lib/img/img.jpg");
$result = $parts['dirname'] . '/' . $parts['filename'];

$result now contains your massaged filename.

Upvotes: 3

Related Questions