3
I have an output that via EXPECT access an equipment and receive 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
===============================================================================";
But depending on the equipment firmware the result comes with a few lines in different positions, however the Labels are always the same.
For example, I want to extract the 1311 values for Service Id and 9014 for MTU,
I tried with the following code to extract the Service Id, but the right result with 4 characters(1311) if it is 5 characters(13211) no longer works.
Does anyone have any idea how to do that?:
$result1 = preg_replace('!\s+!', ' ', $result1);
$posicao = strpos($result1, 'Service Id :');
$service_id_teste = substr($result1, $posicao+13, 4);
echo $service_id_teste;
Thank you very much Bruno, you helped a lot
– Luca Silbernagel