SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,211
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    last two words with the delimiter "."

    If the value of $myVar($_SERVER["SERVER_NAME"]) is "dot.kr",
    I like to get the modified value of $myVar is "dot.kr"

    If the value of $myVar is "www.dot.kr",
    I like to get the modified value of $myVar is "dot.kr"

    If the value of $myVar is "europe.dot.kr",
    I like to get the modified value of $myVar is "dot.kr"

    If the value of $myVar is "france/europe.dot.kr",
    I like to get the modified value of $myVar is "dot.kr"

    If the value of $myVar is "site.com",
    I like to get the modified value of $myVar is "site.com"

    If the value of $myVar is "www.site.com",
    I like to get the modified value of $myVar is "site.com"

    If the value of $myVar is "france/europe.site.com",
    I like to get the modified value of $myVar is "site.com"

    How can I modify $myVar for getting my target value(mainDomain) from each dynamic variable value(subDomain+mainDoamin) ?

    (I like to get the main(registered) domain from the subDomains and mainDomains.)

  2. #2
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php
    
    $domains[] = 'dot.kr';
    $domains[] = 'www.dot.kr';
    $domains[] = 'france/europe.site.com';
    
    foreach($domains as $domain){
    	//This is where the modification starts
    	$domain = explode('.', $domain);
    	$domain_count = count($domain);
    	if($domain_count >= 2) $domain = $domain[$domain_count-2].'.'.$domain[$domain_count-1];
    	else $domain =  $domain[0];
    	//This is where the modification ends
    	echo $domain, '<br>';
    }
    I've exploded the variable on the '.' character and just concatenated the last 2 parts back together. There might be a better way to do this, but that's how I solved it.

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,211
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Zarin Denatrose View Post
    I've exploded the variable on the '.' character and just concatenated the last 2 parts back together. There might be a better way to do this, but that's how I solved it.
    Thank you very much, your code works fine.


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
  •