Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Removing part of a var

    Hi there,

    I have a var which will be something like:

    "./xml/filename.xml"

    I need a way of later cutting down this the "./xml/" from this var so it is simply:
    "filename.xml"

    Is this possible?

    Thanks

  • #2
    Regular Coder
    Join Date
    Jul 2011
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Never mind, Noob here hadn't used explode before. Thanks all.

  • #3
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Well, you could use the str_replace function in php.

    PHP Code:
    $remove './xml/';
    $filename './xml/filename.xml';
    $newfilename trim(str_replace($remove,' '$filename)); 
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #4
    New Coder
    Join Date
    Aug 2010
    Location
    At home with my bunny sleepers.
    Posts
    27
    Thanks
    0
    Thanked 7 Times in 7 Posts
    If all values of your variable is a valid file path, you can just use basename

    PHP Code:
    echo basename('./xml/filename.xml'); //should return filename.xml 
    Choose a job you love, and you will never have to work a day in your life.

    Dolrich Fortich Love to Code Using :)
    [PHP/MySql, Jquery, Codeigniter, Opencart]


  •  

    Posting Permissions

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