www.webdeveloper.com
Results 1 to 4 of 4

Thread: Evaluating Directory names

  1. #1
    Join Date
    Dec 2005
    Posts
    2,984

    Evaluating Directory names

    I'm allowing administrators to create photo albums, each of which will have its own directory. The photo album name will be the directory, only modified to make it a standard web directory. I am changing all white spaces to _, all ' and/or " to nothing and making all letters lowercase. Using regular expressions I do this in three lines

    Code:
    $dirname =~ tr/[A-Z]/[a-z]/;
    $dirname =~ tr/'|"//;
    $dirname =~ tr/\s+/_/;
    But I get some really weird results for the directory name sometimes.....anybody have
    a) ideas as to whats wrong or
    b) a better way?

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    Not exactly what I used, sorry. This is what it was:

    Code:
    $dirname =~ tr/[A-Z]/[a-z]/;
    $dirname =~ tr/\'|\"//;
    $dirname =~ tr/\s+/\_/;

  3. #3
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132
    The information is a little incomplete for an accurate answer...

    But, I'll guess you are posting from a webpage. Are you seeing any URL encoding?. That could give you strange results. Try printing out the 'received' directory name to check.

    I'm not 100% sure, but you may be having problems with your second 2 lines.
    Try these instead...

    $dirname =~ s/('|")//g;
    $dirname =~ s/\s+/_/g;

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    Ridiculous on my part........I tried the substitution (s/) before but I switched to translation (tr/) because it would only get rid of one of the ' or ", but I forgot about the global (g) part of it!!! Thanks a lot Nedals....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles