- preg_match: documentation ( source)
- print_r: documentation ( source)
<?php
$c = " total used free shared buffers cached\nMem: 494 383 111 0 29 200\n-/+ buffers/cache: 153 341\nSwap: 255 0 255";
preg_match("/Mem:\s+(?P<total>\d+)\s+(?P<used>\d+)\s+(?P<free>\d+)\s+(?P<shared>\d+)\s+(?P<buffers>\d+)\s+(?P<cached>\d+)/", $c ,$r);
print_r($r);
preg_match("/Swap:\s+(?P<swapTotal>\d+)\s+(?P<swapUsed>\d+)\s+(?P<swapFree>\d+)/", $c ,$r);
print_r($r);