1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

i need a regex to get the "slug-name"of "slug-name/the/rest/of/the/slug" using php

Discussion in 'PHP' started by free-designer, Nov 30, 2010.

  1. #1
    Hey guys, im not new to php or can't do stuff like that with php, no i can, but the problem is that im not that powerful with regex , so what i need is someone of you guys :) would give me a working regex that would do the following:

    if i have a link like this "page-slug/the/rest/of/the/link"

    i want to strip out the word "page-slug" ONLY , i don't want any of the other words

    ps: this is not a constant url, this may change to any other link at all, all i need is just to get the very first slug and then stop when it met the "/" symbol

    Any other question just ask guys :) ,, Thanks a lot
     
    free-designer, Nov 30, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Might be an easier way, but this will work.

    
    $url = "http://domain.com/page-slug/the/rest/of/the/link";
    
    $url = str_replace("http://","",$url);
    $parts = explode("/", $url);
     
    echo $parts[1]; // = page-slug // $parts[0]; = domain.com // $parts[2]; = the
    
    
    PHP:
     
    MyVodaFone, Nov 30, 2010 IP
  3. free-designer

    free-designer Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wow, Thanks so mush.
    i didn't think of it that way, but this is really helpful you just saved my life ;) Thanks a lot
     
    free-designer, Nov 30, 2010 IP