查找文本并处理 PHP 个变量的值

Find text and handle values to PHP variables

我有硬核。我在 PHP 变量中有这段文本,它来自 SSH 执行的命令,我想将文本提取到变量中。

所以,这是示例文本:

  Huawei Integrated Access Software (MA5683T).
  Copyright(C) Huawei Technologies Co., Ltd. 2002-2013. All rights reserved.

  -----------------------------------------------------------------------------
  User last login information:
  -----------------------------------------------------------------------------
  Access Type : SSH 
  IP-Address  : 0.0.0.0 ssh
  Login  Time : 07.02.2017 20:01:48+01:00
  Logout Time : 07.02.2017 20:01:59+01:00
  -----------------------------------------------------------------------------

MA5683T>enable

MA5683T#display ont autofind all
   ----------------------------------------------------------------------------
   Number              : 1
   F/S/P               : 0/4/0
   Ont SN              : 48575443E1EAC883 (HWTC-E1EAC883)
   Password            : 0x00000000000000000000
   Loid                : 
   Checkcode           : 
   VendorID            : HWTC
   Ont Version         : 635.A
   Ont SoftwareVersion : V3R015C10S106
   Ont EquipmentID     : 010H
   Ont autofind time   : 06.02.2017 11:35:08+01:00
   ----------------------------------------------------------------------------
   Number              : 2
   F/S/P               : 0/4/0
   Ont SN              : 48575443ED9B1582 (HWTC-ED9B1582)
   Password            : 0x00000000000000000000
   Loid                : 
   Checkcode           : 
   VendorID            : HWTC
   Ont Version         : 635.A
   Ont SoftwareVersion : V3R015C10S106
   Ont EquipmentID     : 010H
   Ont autofind time   : 07.02.2017 15:57:35+01:00
   ----------------------------------------------------------------------------
   Number              : 3
   F/S/P               : 0/4/1
   Ont SN              : 48575443E1DA5683 (HWTC-E1DA5683)
   Password            : 0x00000000000000000000
   Loid                : 
   Checkcode           : 
   VendorID            : HWTC
   Ont Version         : 635.A
   Ont SoftwareVersion : V3R015C10S106
   Ont EquipmentID     : 010H
   Ont autofind time   : 07.02.2017 09:20:57+01:00
   ----------------------------------------------------------------------------
   The number of GPON autofind ONT is 3

MA5683T#

我需要提取 "Ont SN"(例如 48575443E1EAC883)和 "F"、"S" 和 "P" 值(F/S/P : 0/4/0在文本中)。

输出将是:

$serial = "48575443E1EAC883"
$f = 0
$s = 4
$p = 0

因为有3条记录,除以------行,所以需要放入数组

谢谢你的建议。

匹配Ont SN:

/Ont SN\s*:\s*([\w]+)/g

https://regex101.com/r/Q7zuk1/1


匹配F/S/P:

/F\/S\/P\s*:\s*(\d+)\/(\d+)\/(\d+)/g

https://regex101.com/r/Q7zuk1/2