Created
March 9, 2021 23:48
-
-
Save jassriver/631bb210100693f326c8fd832ee6ae39 to your computer and use it in GitHub Desktop.
Extrai um endereço de MAC de uma string usando Regex (Expressão regular) com PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// String obtida | |
$macAddress = '10.19.60.72 --- 0x3 Endereço IP Endereço físico Tipo 10.19.63.117 70-85-c2-f6-28-f8 dinâmico'; | |
// Expressão regular pra extrair o MAC ADDRESS | |
preg_match_all('/[a-fA-F0-9-]{17}|[a-fA-F0-9]{12}$/', $macAddress, $mac); | |
// Printa o resultado | |
print_r($mac); | |
/* | |
Resultado: | |
Array ( [0] => Array ( [0] => 70-85-c2-f6-28-f8 ) ) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment