phpcharacter-trimming

How to get a link then take some characters out? PHP


So i made a global.php but on the header i am trying to make it go in between the pages so i can edit it easier so i am using that file but i have it highlight the page on the header you are on so how can i get the link so i can take out the parts?

Here is what i mean:

I have http://16austin16.chalkcraftserver.xyz/Downloads/

And i want to take out most of it to make it just Downloads to make it highlight the page on the header


Solution

  • The quickest way would be to use 'parse_url()'

    Example:

    $url_parts = parse_url("http://16austin16.chalkcraftserver.xyz/Downloads/");
    var_dump($url_parts); // Just showing what parse_url produces
    var_dump($url_parts['path']); // Produces string(11) "/Downloads/"
    
    $simple_name = trim($url_parts['path'], '/');
    echo $simple_name; // Downloads
    

    Check out https://secure.php.net/manual/en/function.parse-url.php