Link to home
Start Free TrialLog in
Avatar of jbclelland
jbclelland

asked on

String search

I have some code stored in a variable that is the output of "ipconfig/all" from a dos command prompt.

I can search through it line by line, but I need to search for a pattern of letters equal to a Mac address of a computer network card.

The code I use at trhe moment is:

// look for 'Physical Address'
foreach ( $lines as $line )
{
  if ( substr($line, 0, 16) == 'Physical Address' )
  {
      $macs[] = substr($line, strlen($line)-17);
  }
}

This code works, but only on english versions of Microsoft. I need it to check it on all language versions of Microsoft.  How can I search for the MAC address string using PHP regular expressions.  I need to search every line in the loop above for the format of characters:

??-??-??-??-??-??

Where ? can be any charachter (so it is six sets of two question marks separated by a - ).

Can you help ?!

Thanks

Ashley :-)
Avatar of Roonaan
Roonaan
Flag of Netherlands image

if(preg_match('/([0-9A-H]{2}(\-[0-9A-H]{2}){5})/', $line, $match)) {
  $macAddress = $line[1];
}

-r-
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial