A
A
Alexander Shapoval2020-05-12 15:22:09
PHP
Alexander Shapoval, 2020-05-12 15:22:09

In the received lines, display only numbers?

Line: [27/Apr/2020:19:14:17 +0000] GET https://domain/api/lead/0/43927/0/0 pid:28254 took:0.171s mem:8mb cpu:58.62% status :200 {54.227.122.223|Zapier}
Regular:

$regex = '/(^\[(?<datetime>.*)\]) (?P<method>OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|PROPFIND) (?P<url>.+?\S) (?P<pid>.+?\S) (?P<took>.+?\S) (?P<mem>.+?\S) (?P<cpu>.+?\S) (?P<status>.+?\S+)/';

Result:
Array
(
    [0] => [27/Apr/2020:19:14:17 +0000] GET https://domain/api/lead/0/43927/0/0 pid:28254 took:0.171s mem:8mb cpu:58.62% status:200
    [1] => [27/Apr/2020:19:14:17 +0000]
    [datetime] => 27/Apr/2020:19:14:17 +0000
    [2] => 27/Apr/2020:19:14:17 +0000
    [method] => GET
    [3] => GET
    [url] => https://domain/api/lead/0/43927/0/0
    [4] => https://domain/api/lead/0/43927/0/0
    [pid] => pid:28254
    [5] => pid:28254
    [took] => took:0.171s
    [6] => took:0.171s
    [mem] => mem:8mb
    [7] => mem:8mb
    [cpu] => cpu:58.62%
    [8] => cpu:58.62%
    [status] => status:200
    [9] => status:200
)

How to get only numeric values ​​in pid, took, mem, cpu, status?
What would be for example
['pid' => 28254, 'cpu' => 58.62]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-05-12
@sanek_os9

pid:(?<pid>\d+) took:(?<took>[.\d]+)\S mem:(?<mem>\d+)\S+ cpu:(?<cpu>[.\d]+)% status:(?<status>\d+)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question