You are here: Re: [PHP] regex and global vars problem « PHP « IT news, forums, messages
Re: [PHP] regex and global vars problem

Posted by Robin Vickery on 10/19/58 11:30

On 10/28/05, Tom Rogers <trogers@kwikin.com> wrote:
>
> I would do it with a small class like this:
>
> <?php
> class mac{
> var $mac='';
> var $is_valid = false;
> function mac($mac){
> $mac = preg_replace('/[^0-9A-F]/','',strtoupper($mac));
> if($this->is_valid = preg_match('/^(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})$/',$mac,$parts)){
> array_shift($parts); //lose the first bit
> $this->mac = implode(':',$parts);
> }
> }
> }
>
> //test
> $mac_list = array("00-aa-11-bb-22-cc","00:aa:11:bb:22:cc","zz:00:11:22:ff:xx","00 aa 11 bb 22 cc");
>
> foreach($mac_list as $mac){
> $mactest = new mac($mac);
> echo "In:$mac";
> if($mactest->is_valid){
> echo " valid $mactest->mac\n";
> }else{
> echo " NOT valid\n";
> }
> }

$mactest = new mac("there are a few gotchas for anyone using this");
print $mactest->is_valid ? "valid\n" : "invalid\n";

// valid

 

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

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