Strip URL into its parts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamjblakey
    New Member
    • Jan 2008
    • 133

    Strip URL into its parts

    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 between the / / and remove the - does anyone know how i can do this.

    Cheers,
    Adam
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I would like to help you, but I always use a javascript routine that returns all elements of an url/uri in an array. If you want that I'll show it. If you insist on PHP code, I'll pass.

    Ronald

    Comment

    • adamjblakey
      New Member
      • Jan 2008
      • 133

      #3
      Originally posted by ronverdonk
      I would like to help you, but I always use a javascript routine that returns all elements of an url/uri in an array. If you want that I'll show it. If you insist on PHP code, I'll pass.

      Ronald
      PHP Only, sorry.

      Cheers for the offer though.

      Comment

      • nomad
        Recognized Expert Contributor
        • Mar 2007
        • 664

        #4
        Originally posted by adamjblakey
        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 between the / / and remove the - does anyone know how i can do this.

        Cheers,
        Adam
        Adam:
        Please take a look at this tread it might help you.


        nomad

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          That ereg_match will result in
          Code:
          /word-word-word/word-word-word.html
          Now when you can live with that, you can find what you want using PHP, as sample:
          [php]
          $text='http://www.website.co. uk/word-word-word/word-word-word.html';
          preg_match_all( "/^(https?:\/\/)?([^\/]*)(.*)/i", "$text", $matches);
          echo dirname($matche s[3][0]);[/php]
          That will give you
          Code:
          /word-word-word
          Ronald

          Comment

          Working...