473,787 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extract domain name

How do you fetch just the domain name part of a variable in a script? The
variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
"http://sub.domain.com/blahblah/whatever/page.htm".

What I need is to extract just the "domain.com ".
Jul 19 '05 #1
2 7410
* Shabam:
How do you fetch just the domain name part of a variable in a script? The
variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
"http://sub.domain.com/blahblah/whatever/page.htm".

What I need is to extract just the "domain.com ".


try something like:

my(undef, undef, $domain) = $s =~
/^(http|ftp|what ever):\/\/(www|ftp|whatev er)\.(.+?)\//;

There might be some module that does what you're looking for (check
CPAN), I didn't look for it, actually...

bye
//Dave

--
Ja, der typische "Ich tippe alles ein was mir ein paar Trottel aus dem
IRC sagen"-Newbie wird aber kein Solaris nutzen... ;)
-- Christoph Gebhardt in bjt
Jul 19 '05 #2
Look for URI module. IMHO, its a good and simple thing for parsing URLs

use URI;
($domain = URI->new("http://www.domain.com/blahblah/whatever/page.htm")->authority) =~ s/^www\.//i
Regards,
Andrew

Shabam wrote on 12 Ноябрь 2004 16:02:
How do you fetch just the domain name part of a variable in a script? The
variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
"http://sub.domain.com/blahblah/whatever/page.htm".

What I need is to extract just the "domain.com ".


--
Andrew
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3175
by: Ren | last post by:
Suppose I have a file containing several lines similar to this: :10000000E7280530AC00A530AD00AD0B0528AC0BE2 The data I want to extract are 8 hexadecimal strings, the first of which is E728, like this: :10000000 E728 0530 AC00 A530 AD00 AD0B 0528 AC0B E2 Also, the bytes in the string are reversed. The E728 needs to be 28E7,
4
2980
by: Alex Ayzin | last post by:
Hi, I have a var-sized URL passed into my method. I need to trim it, so instead of : "123abc.MyDomain.com", I ended up with "MyDomain". The size of the initial string is not fixed. IndexOf wouldn't work, because different domain names are passed every time. I think, I need to use RegEx, but maybe there is some trick that I just didn't think of. Please, advise. Thanks in advance,
0
1276
by: francescomoi | last post by:
Hi. Using Pear XML-RPC, I get this response to a method call: ------------------------------------------ xml_rpc_value Object ( => Array ( => Array (
3
18381
by: deko | last post by:
I'm sure someone has passed this way before... I want to check to see is a domain name is contained in a string, and if one is, I want to extract it. In these strings, domains are always preceded by "http://" or "http : //www" (without the spaces). in pseudo code, I thought it might look like this: if (eregi("http: //", $mystring)) {
5
5122
by: deko | last post by:
If I have random and unpredictable user agent strings containing URLs, what is the best way to extract the URL? For example, let's say the string looks like this: registered NYSE 943 <a href="http://netforex.net"Forex Trading Network Organization </ainfo@netforex.org What's the best way to extract http://netforex.net ?
14
2519
by: deko | last post by:
geturl.php Too much code to paste here, but have a look at http://www.liarsscourge.com/ So far, I have not found a string that can break this... Any built-in functions or suggestions for improvement? Thanks in advance.
5
2197
by: griffin61299 | last post by:
I'm trying to track the logon/off times for Users using certain Event ID's. The entry/example below is the Event Description which is contained in a single cell within my table/report. I need to create a simple query that will extract the Logon ID (just the numbers) - so for the example below, the output would simply be 0x0,0x13BBA434. I've investigated the Mid function but you need a starting position... Unfortunately the start position...
0
743
by: Ciaran | last post by:
Hi what's the best way to extract a var from a string based on a regexp? I can't seem to find the right function. I want to get the domain extension from any url. examples: http://www.domain.com/test.php $extension="com"; http://www.domain.co.uk/test.php $extension="co.uk"; Thanks Ciarn
3
4718
by: Howard Rice | last post by:
Access 2000 (9.0.3821 SR-1) / Windows XP Pro Hi All, Apologies for the newbie question. I am trying to use a simple Query to put a list of e-mail addresses in domain name order (ascending alphabetically) but cannot find a way of extracting only the domain information after the @ character in the complete address string. Of course, the addresses in the source table are of different lengths and so the position of the @ character varies. ...
0
10363
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
10172
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
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
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...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.