envexlabs Posted July 30, 2007 Share Posted July 30, 2007 Hey, I am pulling a value from a database that looks like this: /uploads/images/picture.jpg How would i go about getting just the .jpg? Thanks, envex Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 30, 2007 Share Posted July 30, 2007 strrchr() is what you need. Quote Link to comment Share on other sites More sharing options...
envexlabs Posted July 30, 2007 Author Share Posted July 30, 2007 thanks! Quote Link to comment Share on other sites More sharing options...
ViN86 Posted July 30, 2007 Share Posted July 30, 2007 could also use explode() which would break the string into an array of strings based on the / character. then, count() the array and use the last entry to retrieve the filename (since the last item will always be the file). Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 30, 2007 Share Posted July 30, 2007 alternatively, rather than counting the array and doing things manually, you could use end() to get the last item in the array. Quote Link to comment Share on other sites More sharing options...
ViN86 Posted July 30, 2007 Share Posted July 30, 2007 alternatively, rather than counting the array and doing things manually, you could use end() to get the last item in the array. better yet (ill have to remember that one...) Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 30, 2007 Share Posted July 30, 2007 i always love finding little gems in the PHP manual that make my life easier - that's one of them. Quote Link to comment 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.