Jump to content


Photo

Chop off file paths


  • Please log in to reply
3 replies to this topic

#1 roxii

roxii
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationNorway

Posted 19 May 2006 - 11:17 AM

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.

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

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?

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

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 19 May 2006 - 11:34 AM

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...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 roxii

roxii
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationNorway

Posted 19 May 2006 - 11:36 AM

That's what I'm looking for. Thank you!

#4 yonta

yonta
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 19 May 2006 - 12:45 PM

You could also use the [a href=\"http://pt.php.net/basename\" target=\"_blank\"]basename [/a]function.

do it, do it right, do it right now




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users