Reputation: 2711
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
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
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