Web Analytics Made Easy -
StatCounter Removing part of a var - CodingForum

Announcement

Collapse
No announcement yet.

Removing part of a var

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    Never mind, Noob here hadn't used explode before. Thanks all.

    Comment


    • #3
      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. ^_^

      Comment


      • #4
        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]

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎