I have an output via EXPECT access to an equipment and I get the data below:
$result1 = "
===============================================================================
Service Basic Information
===============================================================================
Service Id : 1311 Vpn Id : 0
Service Type : Epipe
Description : xxxxxxxx
Customer Id : 1312
Last Status Change: 06/11/2017 10:51:13
Last Mgmt Change : 03/24/2017 19:22:10
Admin State : Up Oper State : Up
MTU : 9014
MTU Check : Enabled
Vc Switching : False
SAP Count : 1 SDP Bind Count : 1
Uplink Type: : MPLS
-------------------------------------------------------------------------------
Service Access & Destination Points
-------------------------------------------------------------------------------
Identifier Type AdmMTU OprMTU Adm Opr
-------------------------------------------------------------------------------
sap:lag-10:1311 q-tag 9212 9212 Up Up
sdp:1019:1311 S(192.168.101.19) n/a 0 9190 Up Up
===============================================================================";
However depending on the firmware of the equipment the result comes with some lines in different positions, however the labels are always the same.
For example, I want to extract the values 1311 for Service Id and 9014 for MTU,
I tried with the following code to extract the Service Id, but the result with 4 characters (1311) if it is 5 characters (13211) is no longer working.
Does anyone have any idea how to do this?:
$result1 = preg_replace('!\s+!', ' ', $result1);
$posicao = strpos($result1, 'Service Id :');
$service_id_teste = substr($result1, $posicao+13, 4);
echo $service_id_teste;