473,657 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing subdomains from a string

7 New Member
Hi

Could anyone give me some pointers on how to remove subdomains from a string?

For example:
  • If the string was bytes.com, it would stay bytes.com
  • If it was subdomain.bytes .com, it would become bytes.com
  • If it was subsubdomain.su bdomain.bytes.c om, it would become bytes.com

Essentially, it just needs to strip off the subdomains and produce the root domain if not already present.

Cheers
akadeco
Sep 11 '09 #1
3 6667
micmast
144 New Member
I would suggest explode the string and always take the last 2 values of the returned array.
Sep 11 '09 #2
bvdet
2,851 Recognized Expert Moderator Specialist
To clarify micmast's suggestion, I believe he means split instead of explode.

Expand|Select|Wrap|Line Numbers
  1. >>> s = 'bytes.com'
  2. >>> '.'.join(s.split('.')[-2:])
  3. 'bytes.com'
  4. >>> s = 'subsubdomain.subdomain.bytes.com'
  5. >>> '.'.join(s.split('.')[-2:])
  6. 'bytes.com'
  7. >>> 
Sep 11 '09 #3
micmast
144 New Member
bvdet, yes you are right :) explode is php syntax.

sorry.
Sep 11 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2238
by: steve | last post by:
Hi I am writing an application which ideally requires the creation of subdomains dynamically via asp. However I want all the subdomains to point to 1 asp file, which I wish to use to figure out which subdomain has been typed in the url and to process it appropriately. I was thinking of 2 possible approaches and I am a bit 'cloudly' about both:
3
1777
by: craigkenisston | last post by:
In an application I'm developing I will be using subdomains in the main website to hold some sections of the sites. There will be many serverside generated links that will point to this subdomains. I already have subdomains in a preproduction server and it works fine then, but how do I do that here in my development machine ?? I have WindowsXP SP2, but I don't see anyplace where I can create subdomains, since everything are actually...
2
2745
by: craigkenisston | last post by:
Hi, I create a one day ticket in my authentication code like this : private void btnLogin_Click(object sender, System.EventArgs e) { string _userId = txtUserId.Text; string _password = txtPassword.Text;
4
2034
by: radiax | last post by:
Is there a way to associate or bind a subdomain to a tcp sockets under .net framework (vb.net / c#). I know ip address can be used when using sockets, but the problem is the ip address is shared among subdomains (limited ips supply). Iam looking for possible way to use subdomain.domain.com instead of ip address. Any inputs?? thanks
1
5648
by: Hans Kesting | last post by:
Hi, Is it possible to share sessions between subdomains? Say: the user logs in at www.company.com, and is redirected to my.company.com. This is a different url for the same application. Can I keep the session (so I still know WHO has logged in)? The problem (as I see it) is the session-cookie. If that has a domain of "www.company.com", it will not be transferred to "my.company.com".
8
4302
by: Kenny Lai | last post by:
hey, Is there a way to communicate between iframes on different subdomains? e.g. from one.dot.com to two.dot.com? there is a security access restriction passing javascript commands between subdomains that we've run into. -Kenny
1
3341
by: onequestion | last post by:
Hi friends.. Is it possible to find subdomains on a domain. Can someone help me? currently i'm using this code.. private static String GetSubDomain(URL url) { String host = url.getHost().toString();
9
7793
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept in sessions? I can see active sessions in my mysql database, but is that the only place this information is stored? Sessions and cookies I know are related also, but how specifically (session info stored in cookies?)? Right now, when users...
3
2956
by: Jonathan Wood | last post by:
Perhaps someone who understand Web hosting can offer some insight into this. I have several sites hosted at http://www.crystaltech.com. There were highly recommended and seem pretty good. But this weekend I tried to create some subdomains. For example, subdomain1.domain.com and subdomain2.domain.com. While Crystal Tech supports this, subdomains must point to an IP address. Therefore, it is not possible to point the subdomain to a...
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.