remove everything after slash

Posted on 2010-01-03
Last Modified: 2012-05-08
Whats the best way to remove everything after the trailing slash

so if i had

i would want it to show


Question by:peter2001
    LVL 1

    Accepted Solution

    Either use an framework like Zend framework with its URL/Baseurl functions or do it via string manipulation as shown in code attachment.

    The line takes your original string, finds the first occurende of //, and goes from there (exluding the //, what is the meaning of the +2) to the next /, then it adds 1 more character to include teh final / you mentioned.

      $string = '';
      $newString = substr ( $string, 0 , (strpos($string,'/',strpos($string,'//')+2))+1 );		

    Open in new window

    LVL 1

    Author Comment

    That works great thanks for the help
    LVL 1

    Author Closing Comment

    cheers and thanks for the explanation

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now