Jump to content

Archived

This topic is now archived and is closed to further replies.

roxii

Chop off file paths

Recommended Posts

Gah, I never know what to use when I get into this type of situation. I'm using ftp_nlist to gather the files in a directory, but I need to get rid of the path in front of the files.

[code]
<?php
$contents = ftp_nlist($conn, "/public_html/assets/files");
print_r($contents);
?>
[/code]

That will print out:

Array(
[0] => /public_html/assets/files/1.jpg
[1] => /public_html/assets/files/2.jpg
)

All I want is the 1.jpg, 2.jpg, etc.

What would be an appropriate function to use to chop off the last slash and everything before it?

[b]EDITED BY WILTEEN88: PLEASE USE [ CODE][/CODE] (without the space) TAGS RATHER THAN [code=php:0][/code] TAGS AS PHPTAGS NO LONGER EXIST. THANK YOU.[/b]

Share this post


Link to post
Share on other sites
The answer is right on phpfreaks

[a href=\"http://www.phpfreaks.com/phpmanual/page/function.strrchr.html\" target=\"_blank\"]http://www.phpfreaks.com/phpmanual/page/fu...on.strrchr.html[/a]

Lite...

Share this post


Link to post
Share on other sites
You could also use the [a href=\"http://pt.php.net/basename\" target=\"_blank\"]basename [/a]function.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.