SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot clarnp49's Avatar
    Join Date
    Sep 2004
    Location
    Bowie MD
    Posts
    184
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Count Chars and Delete

    How do I take a string like this:

    \manuals\filename.pdf

    and delete \manuals\ from it so that I can display filename.pdf

    I am looking to edit the filename but don't want to view the \manual when the customer does the updates because the folder doesn't ever change.

    Thanks!
    If it works don't fix it. If it's broke fix it.
    He who knows all is the smartest.
    He who doesn't know anything isn't dumbest.

  2. #2
    SitePoint Enthusiast mithra62's Avatar
    Join Date
    Nov 2004
    Location
    Van Nuys
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    <?php
    $file_name = "\manuals\filename.pdf";
    $file_name = str_replace("\manuals\", $file_name);
    ?>

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $str='\manuals\filename.pdf';
    $arr explode('\\'$str);
    echo 
    $arr[count($arr) - 1]; 

  4. #4
    SitePoint Enthusiast SecondV's Avatar
    Join Date
    Jan 2006
    Location
    Kentucky
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ltrim();
    PHP Code:
    <?php

    $str 
    '\manuals\filename.pdf';
    echo 
    ltrim($str'\\manuals\\');

    ?>

  5. #5
    SitePoint Enthusiast SecondV's Avatar
    Join Date
    Jan 2006
    Location
    Kentucky
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mithra62
    try
    <?php
    $file_name = "\manuals\filename.pdf";
    $file_name = str_replace("\manuals\", $file_name);
    ?>
    Btw : Parse error: parse error in ...

    Need to escape \

    PHP Code:
    <?php
    $file_name 
    "\manuals\filename.pdf";
    $file_name str_replace("\\manuals\\"$file_name);
    ?>
    Last edited by SecondV; Apr 25, 2006 at 15:38. Reason: Oops, sorry 'bout that.. double post.

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP has a function for this, you don't have to write your own code:
    http://us2.php.net/basename

  7. #7
    SitePoint Zealot clarnp49's Avatar
    Join Date
    Sep 2004
    Location
    Bowie MD
    Posts
    184
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    100000000 points for Dan Grossman!!!!
    Thanks! How come I didn't see that in the manual?
    If it works don't fix it. If it's broke fix it.
    He who knows all is the smartest.
    He who doesn't know anything isn't dumbest.

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I stumbled across it while browsing image functions for someone else's thread. Ya learn something new every 5 minutes on this forum...


Bookmarks

Posting Permissions

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