stijnvb Posted February 13, 2011 Share Posted February 13, 2011 What I want to do is simple: The string "this_is_an_example.php" should return "this_is_an_" while: "this_is_an_example_filename.php should return "this_is_an_example_" Is there a simple function which can cut off the part after the last _ ? I have been looking and trying several functions, but can't seem to find the right one for this. (the last _ being cut off of course wouldn't be a problem I couldn't live with :-) ) Any help will be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
stijnvb Posted February 13, 2011 Author Share Posted February 13, 2011 I could probably use explode and put everything together except the last part ... but I'm pretty sure there's a built-in function for this ... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 13, 2011 Share Posted February 13, 2011 Here's one way of doing this: <?php function tester($str,$delim='_') { $tmp = explode($delim,$str); $dmy = array_pop($tmp); return (implode($delim,$tmp) . $delim); } echo tester("this_is_an_example_filename.php"); ?> Ken Quote Link to comment Share on other sites More sharing options...
stijnvb Posted February 13, 2011 Author Share Posted February 13, 2011 Ken, You offered me more than I asked! Does exactly what I needed! It's not a built in function, but don't think that really matters if I don't even have to write it myself!!! Thanks! Stijn 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.