S
S
SteepNET2020-08-12 13:07:41
PHP
SteepNET, 2020-08-12 13:07:41

How to select phone numbers from a string?

Good afternoon! I ask for help to remove unnecessary from the output to php

The output is

Channel: Exten: CLCID: ========================================================================================== Channel: PJSIP/739-00009cf3/Dial Up 00:01:15 Exten: s CLCID: "CID:9622088888" <79379853222> Channel: PJSIP/814-00009cf5/Dial Up 00:00:25 Exten: s CLCID: "CID:9622088888" <89119120799> Channel: PJSIP/BEELINE_9622088888-00009cf4/AppDial Up 00:01:13 Exten: CLCID: "" <9622088888> Channel: PJSIP/BEELINE_9622088888-00009cf6/AppDial Up 00:00:25 Exten: CLCID: "" <9622088888> Objects found: 4


I'm trying to select here
1. 739 is from PJSIP/739-00009cf3/ this number can of course be anything but always 3 digits
2. +79379853222 is from <+79379853222>

And output something like {"739":"+79379853222"}
And if you still get time to wrap up here, it will be space in general!
{"739":"+79379853222":"00:01:15"}
There can be several different numbers in the Output, here I stuck in how to separate them, how to extract them I don’t know
And these are Channel: PJSIP/BEELINE_9622088888-00009cf4/ inappropriately, you only need to

isolate 3-digit numbers
.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-08-12
@SteepNET

https://regex101.com/r/qVEDaP/1
PJSIP/(\d+)\S+ Up ([\d:]+).+?<(\d+)>

$str = '
Channel: Exten: CLCID: ========================================================================================== Channel: PJSIP/739-00009cf3/Dial Up 00:01:15 Exten: s CLCID: "CID:9622088888" <79379853222> 
Channel: PJSIP/814-00009cf5/Dial Up 00:00:25 Exten: s CLCID: "CID:9622088888" <89119120799> 
Channel: PJSIP/BEELINE_9622088888-00009cf4/AppDial Up 00:01:13 Exten: CLCID: "" <9622088888> 
Channel: PJSIP/BEELINE_9622088888-00009cf6/AppDial Up 00:00:25 Exten: CLCID: "" <9622088888> 
Objects found: 4
';

preg_match_all('~PJSIP/(\d+)\S+ Up ([\d:]+).+?<\K\d+~s', $str, $m, PREG_SET_ORDER);

print_r($m);

V
Vitaliy K, 2020-08-12
@revenger

Try further.
Nobody will do it for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question