kernelgpf Posted July 18, 2008 Share Posted July 18, 2008 I'm bad at parsing and was wondering if someone could whip up a bit of code to take a file name out of a directory URL. Here's an example- /home/wildtail/public_html/autopics/breedable/natural/manetail/black.png I need it to just take the actual file name (black.png) out from the rest, scrap the rest, and then remove the .png on the end so all that's left is "black", but it's different with different file names, obviously. Pre-thanks! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 18, 2008 Share Posted July 18, 2008 <?php $string = "/home/wildtail/public_html/autopics/breedable/natural/manetail/black.png"; $bits = explode("/",$string); $file = $bits[count($bits)-1]; list($name,$ext) = explode(".",$file); echo "The name is: ".$name."<br />The extension is: ".$ext; ?> Quote Link to comment Share on other sites More sharing options...
kernelgpf Posted July 18, 2008 Author Share Posted July 18, 2008 Works wonders, thanks so much! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 Even easier -- use the function pathinfo() <?php $string = "/home/wildtail/public_html/autopics/breedable/natural/manetail/black.png"; echo pathinfo($string,PATHINFO_FILENAME); ?> Ken 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.