d22552000 Posted November 14, 2007 Share Posted November 14, 2007 Yes, this is almost like PARSE_URL, but no this is not what I want to do. Simplest way to explain it is by example. I want to turn this: ./`admin/plugins/top/*.php Into this: * I want to get the name of the script IN the file. The files PATH, is not going to be /`admin/plugins/top/. The paths will be ./`admin/plugins/* (top | middle | bottom). How would I convert these names? Link to comment https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/ Share on other sites More sharing options...
gin Posted November 14, 2007 Share Posted November 14, 2007 I'm not sure if I'm understanding correctly, but if all you want is the filename you can use basename(). Link to comment https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/#findComment-391142 Share on other sites More sharing options...
tippy_102 Posted November 14, 2007 Share Posted November 14, 2007 $filename = basename($_SERVER[sCRIPT_FILENAME], ".php"); Link to comment https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/#findComment-391143 Share on other sites More sharing options...
d22552000 Posted November 15, 2007 Author Share Posted November 15, 2007 nope, I am doing this: Scanning a directory for files using glob creating a header (h#) for them using their NAME eval'ing these files to add them to this script im in. ending that header block (/h#) currently im doing this a very long way: <?PHP function parse_plugin($con,$file) { $file = str_replace('./`admin/plugins/','',$file); $file = str_replace('bottom','',$file); $file = str_replace('middle','',$file); $file = str_replace('top','',$file); $file = str_replace('.php','',$file); $file = str_replace('/','',$file); begin_frame($file,true); eval($con); end_frame(); } foreach(glob('./`admin/plugins/top/*.php') as $file) { parse_plugin(file_get_contents($file),$file); } //--bunch of script--// foreach(glob('./`admin/plugins/middle/*.php') as $file) { parse_plugin(file_get_contents($file),$file); } //--bunch of script--// foreach(glob('./`admin/plugins/bottom/*.php') as $file) { parse_plugin(file_get_contents($file),$file); } ?> Link to comment https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/#findComment-391892 Share on other sites More sharing options...
gin Posted November 15, 2007 Share Posted November 15, 2007 You can explode, I suppose. Though I still think basename would work. Have you actually tried it? Link to comment https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/#findComment-391909 Share on other sites More sharing options...
trq Posted November 15, 2007 Share Posted November 15, 2007 You really need to explain your question alot clearer. Given a filepath, basename returns the file name. eg; #!/usr/bin/php <?php foreach (glob('~/scratch/*.php') as $filepath) { echo "$filepath : " . basename($filepath) . "\n"; } ?> returns.... /home/thorpe/scratch/abs.php : abs.php /home/thorpe/scratch/ch.php : ch.php /home/thorpe/scratch/filter.php : filter.php on my machine. Link to comment https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/#findComment-391965 Share on other sites More sharing options...
d22552000 Posted November 20, 2007 Author Share Posted November 20, 2007 ya sorry, I didn't have time to look up basename at the time, thanks for your guy's help. Basename did it. Link to comment https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/#findComment-394871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.