SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    A way to extract www or test from the URL

    I've created a subdomain that I can use for testing purposes. Is there a way to extract either www or test from the URL?

    test.example.com

    vs.

    www.example.com

    Links on the webpage will dynamically point to the right place if I can get this figured out.

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I don't know if there's a php function to do this, but i just came up with this.

    PHP Code:
    $str 'test.domain.com';
    $temp explode('.'$str);
    $subdomain implode('.'array_splice($temp0, -2)); 
    echo 
    $subdomain

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You could just use links relative to the http root. Might make things easier.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,796
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    The BEST solution would depend on what method you are using to get the URL in the first place.
    but let say you have managed to get the URI into a sting before you finally echo it.
    SINCE you know the length of your old domain=4, why not do this:

    $URI="test.yourdomain.com";
    $URI="www".sbstr($URI,4);// deletes the first four characters... eg.:'TEST' and adds 'www'


    hope that helps


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •