@@ -66,21 +66,34 @@ private function parseData($dataString)
66
66
{
67
67
$ output = array ();
68
68
$ field = array ();
69
+ $ currentField = "" ;
69
70
foreach (explode ("\n" , $ dataString ) as $ line ) {
70
71
$ trimmedLine = trim ($ line );
71
- if ($ trimmedLine === '--- ' || $ trimmedLine === '' ) {
72
+
73
+ // ($trimmedLine === '' && $currentField != 'FieldValue')
74
+ // Don't start new field for an empty line in a multi-line FieldValue
75
+ if ($ trimmedLine === '--- ' || ($ currentField !== 'FieldValue ' && $ trimmedLine === '' )) {
72
76
// Block completed; process it
73
77
if (sizeof ($ field ) > 0 ) {
74
78
$ output [] = $ field ;
75
79
}
76
80
$ field = array ();
77
81
continue ;
78
82
}
83
+
79
84
// Process contents of data block
80
85
$ parts = explode (': ' , $ line );
81
86
$ key = null ;
82
87
$ value = null ;
83
88
89
+ //Continue through lines already processed from FieldValue
90
+ if ($ currentField === 'FieldValue '
91
+ && $ parts [0 ] !== 'FieldJustification '
92
+ && !empty ($ field ['FieldValue ' ])){
93
+
94
+ continue ;
95
+ }
96
+
84
97
// Handle colon in the value
85
98
if (sizeof ($ parts ) !== 2 ) {
86
99
$ key = $ parts [0 ];
@@ -90,6 +103,13 @@ private function parseData($dataString)
90
103
91
104
$ key = $ key ?: trim ($ parts [0 ]);
92
105
$ value = $ value ?: trim ($ parts [1 ]);
106
+
107
+ if ($ currentField === 'FieldValue ' && !empty ($ value )) {
108
+ $ value = $ this ->getFieldValue ($ line ,$ dataString );
109
+ } else if ($ currentField === 'FieldValue ' ){
110
+ $ value = "" ;
111
+ }
112
+
93
113
if (isset ($ field [$ key ])) {
94
114
$ field [$ key ] = (array ) $ field [$ key ];
95
115
$ field [$ key ][] = $ value ;
@@ -106,4 +126,35 @@ private function parseData($dataString)
106
126
107
127
return $ output ;
108
128
}
129
+
130
+ /**
131
+ * Parses a FieldValue for Multiple Lines e.g.
132
+ * FieldValue: Text
133
+ *
134
+ * MoreText
135
+ * Something
136
+ * ExtraText
137
+ * OtherText
138
+ *
139
+ * FieldJustification: Left
140
+ *
141
+ * @param string $line The current line being searched
142
+ * @param string $dataString
143
+ * @return bool|string Returns a string containing the value for FieldValue e.g. Text\n\nMoreText\nSomething etc.
144
+ */
145
+ private function getFieldValue ($ line , $ dataString )
146
+ {
147
+ // Offset 'FieldValue:'
148
+ $ pos1 = strpos ($ dataString , $ line ) + 11 ;
149
+ $ pos2 = strpos ($ dataString , "FieldJustification " , $ pos1 );
150
+ $ length = $ pos2 - $ pos1 ;
151
+
152
+ $ value = substr (
153
+ $ dataString ,
154
+ $ pos1 ,
155
+ $ length
156
+ );
157
+
158
+ return $ value ;
159
+ }
109
160
}
0 commit comments