Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005
    Posts
    46

    Unanswered: Truncate File name...

    I am using a script that lists all of the files in a certain directory, for example, the page will list:

    1.jpg
    22.jpg
    3.jpg etc

    I want to remove the extension. I figure the best and easiest way would be to have the script calculate the length of the file name, and then subtract "4" and then post the remaining charcters:

    1
    22
    3

    Is there an easy and simple way to do this, oh wise phpers!

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Taking the last 4 characters off is one way to do it. Or you could take everything off after the last period (if there are file extension lengths are not always 3 characters). You can do this many different ways.

    You'll probably want to use some combination of substr, strrpos, strpos, strlen, or maybe even explode.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •