URL Stripping

Discussion in 'PHP' started by adamjblakey, Feb 14, 2008.

  1. #1
    Hi,

    I am trying to strip down a url like this:

    http://www.website.co.uk/word-word-word/word-word-word.html

    I just want to extract the bold section above between the / / and remove the - does anyone know how i can do this.

    Cheers,
    Adam
     
    adamjblakey, Feb 14, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    This will extract what you want:

    
    <?php
    
    $url = 'http://www.website.co.uk/word-word-word/word-word-word.html';
    
    $parts = parse_url($url);
    
    list($junk, $want, $junk) = explode('/', $parts['path'], 3);
    
    echo $want;
    ?>
    
    PHP:
    Output:

    
    word-word-word
    
    Code (markup):
    Jay

    --

    If this post helped, a reputation would be appreciated :)
     
    jayshah, Feb 14, 2008 IP
    adamjblakey likes this.
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Thank you for this jayshah, how will i get the url to start with as they will be different.
     
    adamjblakey, Feb 14, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    $_server['request_uri']

    EDIT:

    The forum converted it to lowercase, but it should all be uppercase.
     
    nico_swd, Feb 14, 2008 IP
  5. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Exactly what nico_swd said. Just to confirm, it's:

    
    $url = $_SERVER['REQUEST_URI'];
    
    PHP:
    Replace the $url = ... line with that one.

    Jay
     
    jayshah, Feb 14, 2008 IP
  6. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Thanks a lot guys :)
     
    adamjblakey, Feb 14, 2008 IP