Hi,

Thursday, October 27, 2005, 3:15:30 AM, you wrote:
JG> I am having a problem with a couple of function I have written to check
JG> for a type of string, attempt to fix it and pass it back to the main
JG> function.  Any help is appreciated.

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";
  }
}

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to