You are here: Re: display provider name form hostname « PHP Programming Language « IT news, forums, messages
Re: display provider name form hostname

Posted by Rik on 08/04/06 11:53

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация