PHP preg_match_all() Matching
I want to match FDSize: <value>
in the following:
Gid: 48 48 48 48
FDSize: 64
Groups: 48 425
VmPeak: 289928 kB
开发者_StackOverflow中文版
It comes from /proc/status
<value>
is not a fixed length, and neither are the lines above or below.
Try something like this:
preg_match_all('`FDSize: (\\d+)`s', $subject, $matches);
print_r($matches);
Not really sure why/how/when you have to do this. I should've asked questions before posting an answer but i didn't. Here are some ways to get that out of a line though...
$line = 'Gid: 48 48 48 48 FDSize: 64 Groups: 48 425 VmPeak: 289928 kB';
// in a loop...
echo current( explode(' ', end( explode( 'FDSize: ', $line ) ) ) );
// or
preg_match_all('~fdsize: (\d+)~i', $line, $matches);
$mystr='Gid: 48 48 48 48 FDSize: 64 Groups: 48 425 VmPeak: 289928 kB';
$str = explode(":",$mystr);
foreach($str as $k=>$word){
if(strpos($word,"FDSize") !== FALSE){
print $str[$k+1];
}
}
try
preg_match_all("/FDSize:\s([0-9]+)/msiU", $data_in, $matches);
精彩评论