473,237 Members | 1,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

display provider name form hostname

Hi,

I only want to display the provider name from a hostname, so I need to
divide the string to take only de characters from after the before last dot.

For example:

dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"

adsl-dc-4d454.adsl.wanadoo.nl -I only wanna display "wanadoo.nl"
I tried with "substr()", but than you have to know the exact positions, and
that's different in a hostname.

Anybody knows if this possible?

kind regards,

Eric
Aug 4 '06 #1
6 3564
Hi,
>
I only want to display the provider name from a hostname, so I need to
divide the string to take only de characters from after the before last
dot.

For example:

dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"

adsl-dc-4d454.adsl.wanadoo.nl -I only wanna display "wanadoo.nl"
I tried with "substr()", but than you have to know the exact positions,
and that's different in a hostname.

Anybody knows if this possible?

kind regards,

Eric
i found this solution:

<?php
$host = "dsl-083-247-088-130.solcon.nl";

$char = 2;
$_count_dot = 0;
while ($count_dot != 2){
$char++;
$dot = substr($host, -$char, 1);
if ($dot == "."){
$count_dot++;
}
}
echo substr($host, -$char+1);
?>
Aug 4 '06 #2
Rik
Eric Rechter wrote:
>Hi,

I only want to display the provider name from a hostname, so I need
to divide the string to take only de characters from after the
before last dot.

For example:

dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"

adsl-dc-4d454.adsl.wanadoo.nl -I only wanna display "wanadoo.nl"
I tried with "substr()", but than you have to know the exact
positions, and that's different in a hostname.

Anybody knows if this possible?

kind regards,

Eric

i found this solution:

<?php
$host = "dsl-083-247-088-130.solcon.nl";

$char = 2;
$_count_dot = 0;
while ($count_dot != 2){
$char++;
$dot = substr($host, -$char, 1);
if ($dot == "."){
$count_dot++;
}
}
echo substr($host, -$char+1);

Maybe this is part of a solution:
http://www.php.net/manual/nl/function.parse-url.php

Else, your code shorter:
$string = "dsl-083-247-088-130.solcon.nl";
preg_match('/[^.]+\.[^.]+$/',$string,$match);
$host = $match[0];

Grtz,
--
Rik Wasmus
Aug 4 '06 #3
"Eric Rechter" <er*********@solcon.nlwrote:
I only want to display the provider name from a hostname, so I need to
divide the string to take only de characters from after the before last dot.

For example:

dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"
$hostname = "dsl-083-247-088-130.solcon.nl";
$parts = explode('.', $hostname);
if (count($parts) >= 2)
$provider_name =
$parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
else
$provider_name = $hostname;

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Aug 5 '06 #4
Rik
Miguel Cruz wrote:
"Eric Rechter" <er*********@solcon.nlwrote:
>I only want to display the provider name from a hostname, so I need
to divide the string to take only de characters from after the
before last dot.

For example:

dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"

$hostname = "dsl-083-247-088-130.solcon.nl";
$parts = explode('.', $hostname);
if (count($parts) >= 2)
$provider_name =
$parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
else
$provider_name = $hostname;
Well, if we're going that way:
$host = implode('.',array_slice(explode('.',$hostname),-2));

Grtz,
--
Rik Wasmus
Aug 5 '06 #5
"Rik" <lu************@hotmail.comwrote:
Miguel Cruz wrote:
>"Eric Rechter" <er*********@solcon.nlwrote:
>>I only want to display the provider name from a hostname, so I need
to divide the string to take only de characters from after the
before last dot.

For example:

dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"

$hostname = "dsl-083-247-088-130.solcon.nl";
$parts = explode('.', $hostname);
if (count($parts) >= 2)
$provider_name =
$parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
else
$provider_name = $hostname;

Well, if we're going that way:
$host = implode('.',array_slice(explode('.',$hostname),-2));
You win this time... but I'll be back!

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Aug 6 '06 #6
Rik
Miguel Cruz wrote:
"Rik" <lu************@hotmail.comwrote:
>Miguel Cruz wrote:
>>"Eric Rechter" <er*********@solcon.nlwrote:
I only want to display the provider name from a hostname, so I need
to divide the string to take only de characters from after the
before last dot.

For example:

dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"

$hostname = "dsl-083-247-088-130.solcon.nl";
$parts = explode('.', $hostname);
if (count($parts) >= 2)
$provider_name =
$parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
else
$provider_name = $hostname;

Well, if we're going that way:
$host = implode('.',array_slice(explode('.',$hostname),-2));

You win this time... but I'll be back!
Hehehe, oneliners are fun to make up, but often a terrible thing in real
code :-). It's usually better to be a bit more verbose to keep the code
legible for future coders. (Even for yourself after a year. I've cursed my
own cryptic code quite often in the past).

Grtz,
--
Rik Wasmus
Aug 6 '06 #7

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

Similar topics

2
by: erica | last post by:
Hi, I am currently writing PHP code for some polling software. When someone votes, it stores their IP address in the database. From then on, they cannot vote in that particular poll, they only...
4
by: dmiller23462 | last post by:
Somebody take a look and give me any suggestions? My brain is nuked... Here's my deal....I have online submission forms on my intranet at work here....I am appending to an Access DB with the...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
2
by: magix | last post by:
Hi, I'm using Access Database with ASP. There is one particular thing that I have issue with. My purpose is for user to update their own profile. Their existing profile information will be...
3
by: SurfboY | last post by:
How can I get the internet connection and provider of a visitor on my website? I know how to get the hostname, but I see some webstats are able to detect much more and get the provider's name etc
1
by: sunnyluthra1 | last post by:
Hi Everyone, I am working on a piece of code, that displays the properties(Name, Datatype, size & Description) of the table in the database. Now I want to further Enhance the code. I Have created...
2
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
4
by: giandeo | last post by:
Hello experts. I wish to post a string and display the output in the same page. The Scenario: Table name: importer Field name: imp_code, imp_sname, imp_address, imp_tel I have a page...
2
by: pozze | last post by:
Hi, I need to display images and other record information retrieved from an SQL 2005 database in a datagrid on a web page. I'm coding in VB .net I have recently changed over from VB ASP and i'm...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.