Adding a tag in a line after every 12-digit number

I have a line from an HL7 message (lab results) and you need to add a line break after every 12-digit number.

Example line:

1    NM    2951-2  S Sodium:  LN     144    mmol/L  mmol/L    135-145       F      201402150533      2    NM    2823-3  S Potassium:  LN     5.6    mmol/L  mmol/L    3.5-5.5    H      F      201402150533      3    NM    2075-0  S Chloride:  LN     103    mmol/L  mmol/L    95-110       F      201402150533

Since the 12-digit string is the date and timestamp, this will change every test.

+4
source share
1 answer

Good time to use regex (see preg_replace ):

$str = preg_replace('/\d{12}/', '$0<br>', $str);

replaces each line of 12 numeric digits with the same line that follows <br>.

+6
source

All Articles