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! Link to comment https://forums.phpfreaks.com/topic/115349-parsing-help/ 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; ?> Link to comment https://forums.phpfreaks.com/topic/115349-parsing-help/#findComment-593034 Share on other sites More sharing options...
kernelgpf Posted July 18, 2008 Author Share Posted July 18, 2008 Works wonders, thanks so much! Link to comment https://forums.phpfreaks.com/topic/115349-parsing-help/#findComment-593035 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 Link to comment https://forums.phpfreaks.com/topic/115349-parsing-help/#findComment-593048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.