473,671 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.wana doo.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 3590
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.wana doo.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.wana doo.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,$matc h);
$host = $match[0];

Grtz,
--
Rik Wasmus
Aug 4 '06 #3
"Eric Rechter" <er*********@so lcon.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*********@so lcon.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('.',arr ay_slice(explod e('.',$hostname ),-2));

Grtz,
--
Rik Wasmus
Aug 5 '06 #5
"Rik" <lu************ @hotmail.comwro te:
Miguel Cruz wrote:
>"Eric Rechter" <er*********@so lcon.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('.',arr ay_slice(explod e('.',$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.comwro te:
>Miguel Cruz wrote:
>>"Eric Rechter" <er*********@so lcon.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('.',arr ay_slice(explod e('.',$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
1965
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 view the results. There are several polls in the database, and there is a field called "status". When it is 0, the poll is "active" and can be voted upon. When it is 1, it is archived and one can only view the results. But, there seems to be...
4
1795
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 input from all HTML fields and then querying aforementioned DB with different variables (search by name, wave, reason, etc). The output that I'm getting (SELECT * 'cause I need all of the data included in the search) I would like to display in a nice...
19
6872
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 JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
2
2529
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 display in Edit Form format. The problem is if the field has space, the second word will not display, when I display in input text format. E.g if My first name "User_FirstName" in my table has entry, let say "David
3
1852
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
3696
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 a form in MS Access, on that form, I have 2 buttons & a text box. One button is to select a mdb file, whom properties i want to display. Second button then stores that properties in a Excel file. when I open the file using first button, the path of...
2
3088
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 that dynamically pulls info from my database to populate a drop down menu. Upon an onChange event, I wish to display the fields related to that pull down menu WITHOUT SUBMITTING THE PAGE. The Senario: Database name: sp.mdb
4
2521
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 which consists of
2
2795
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 still getting used to .net I can successfully upload images and other data into the SQL Database, I'm currently storing RecordID, File Name, Type of File (mime), File Size, and File Data. I can retreive non binary data to a datagrid but I cannot...
0
8909
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
8819
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...
1
8596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
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...
1
6222
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
4221
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
2806
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
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
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.