我有以下字符串:的preg_match話後面數字
Query_time: 77.571216 Lock_time: 2.793139 Rows_sent: 20 Rows_examined: 4654071
我怎麼會去把每數到一個變量? 如:
$query_time = 77.571216;
$lock_time = 2.793139;
$rows_sent = 20;
$rows_examined = 4654071;
我有以下字符串:的preg_match話後面數字
Query_time: 77.571216 Lock_time: 2.793139 Rows_sent: 20 Rows_examined: 4654071
我怎麼會去把每數到一個變量? 如:
$query_time = 77.571216;
$lock_time = 2.793139;
$rows_sent = 20;
$rows_examined = 4654071;
if (preg_match('/Query_time: ([0-9.]+) Lock_time: ([0-9.]+) Rows_sent: ([0-9.]+) Rows_examined: ([0-9.]+)/', $string, $matches)) {
list($query_time, $lock_time, $rows_sent, $rows_examined) =
array_slice($matches, 1);
}
$str = 'Query_time: 77.571216 Lock_time: 2.793139 Rows_sent: 20 Rows_examined: 4654071';
list($null, $query_time, $lock_time, $rows_sent, $rows_examined) = preg_split('/\S+:/',$str);
幾乎相同的答案k102有輕微的變化,我使用的標誌PREG_SPLIT_NO_EMPTY,所以沒有必要必須在的開始一個$空VAR列表:)
$str = 'Query_time: 77.571216 Lock_time: 2.793139 Rows_sent: 20 Rows_examined: 4654071';
list($query_time, $lock_time, $rows_sent, $rows_examined) = preg_split('/\S+:/',$str, 0, PREG_SPLIT_NO_EMPTY);