如何从此函数中获取特定文本?

阿修罗91

我想知道如何Physical Address. . . . . . . . . : xx-xx-xx-xx-xx-xx$cmd = system('ipconfig /all').

当我写作时$ cmd = system('ipconfig /all'),我的屏幕上会显示一个文本。即使没有呼应$cmd. 如何删除文本但文本的某些部分。我想得到38 chars文本Physical Address

注意:更重要的是摆脱显示的文本system('ipconfig /all')但仍将其包含在变量中

西莫斯·法苏利奥蒂斯

您需要测试一下,因为我不确切知道您的 IPCONFIG 结果(因操作系统而异),但这里非常接近您想要的结果:

<?php
$command = "ipconfig /all";
$output = shell_exec($command);
$output = explode(PHP_EOL, $output);
$output = $output[0];
$result = explode("Physical Address",$output);
echo substr($result[1],20,17);
?>

请记住,您可能需要更改echo substr($result[1],20,15);以满足您的需求,因为它会根据您拥有的网卡数量等而有所不同。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章