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/06/06 13:53

Miguel Cruz wrote:
> "Rik" <luiheidsgoeroe@hotmail.com> wrote:
>> Miguel Cruz wrote:
>>> "Eric Rechter" <erikrechter@solcon.nl> wrote:
>>>> 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

 

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

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