Please help with code for url

Discussion in 'PHP' started by JEET, Apr 27, 2006.

  1. #1
    JEET, Apr 27, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $url="http://www.domain.com/folder/page.php?id=12";
    $pieces = explode("/", $url);
    echo $pieces[0];
    echo $pieces[1];
    echo $pieces[2]; 
    echo $pieces[3]; 
    PHP:
    This splits apart the url at each /

    http://uk2.php.net/explode
     
    mad4, Apr 27, 2006 IP
  3. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #3
    the above code will work but will return a few unwanted pieces this may be more useful


    
          $url="http://www.domain.com/folder/page.php?id=12";
          $url = str_replace("http://", "", $url);
          $pieces = explode("/", $url);
          echo $pieces[0];
          echo $pieces[1];
          echo $pieces[2];
          echo $pieces[3]; 
    
    Code (markup):
    it just takes the first http:// out of the url so you wont endup with 2 blank array keys at the start
     
    Danny, Apr 27, 2006 IP
    mad4 likes this.
  4. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #4
    Oh also this means that you wont need to echo out the other pieces your URL will now be held in

    $piece[0];
     
    Danny, Apr 27, 2006 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Hi guys,
    Thanks so much for the help.
    Both your codes were exactly what I was looking for.
    Excluding the http:// part is very useful.

    Another thing,
    Can you guys please suggest some help on MY-SQL creation ? Something which a total newbe like me can follow...
    I looked at the w3schools help but wasn't able to follow a single word. Is there a website which takes me stepwise from creating a database,
    to creating tables,
    populating them,
    retrieving information from them,
    putting information in them when user fills a form on my site etc.

    Basically what I need to do is:
    Create a database with the following tables.
    username, password, email, user defined page, user input 1, user input 2, user input 3
    All the fields except "username" can be modified later from the user's settings.
    Then I also want user input1, user input 2, user input 3 displayed on "user defined page" created on the fly.
    The username is the identifying field to get appropriate field from database.

    Although I am unaware of how to do all that.

    I know how to create a database using Cpanel. But am totally stupid if you ask me to create a table in it and then fill it.
    And again, So many thanks for both the codes above.
    Thank you
    jeet
     
    JEET, Apr 28, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Install phpmyadmin on your site and you will be able to do everything you ever want with databases.

    You will also learn stuff while you use it.
     
    mad4, Apr 28, 2006 IP
  7. pedrotuga

    pedrotuga Peon

    Messages:
    162
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    or use a client site front end like mysqlfront
     
    pedrotuga, Apr 28, 2006 IP
  8. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #8
    Hi,
    Thanks for those.
    I already have phpmyadmin on my server and it's time to explore it...
    Thank you guys.
    Best wishes
    jeet
     
    JEET, Apr 28, 2006 IP