@@ -295,17 +295,20 @@ public function generate($tableData = null)
295295
296296 // Is there a table heading to display?
297297 if (! empty ($ this ->heading )) {
298- preg_match ('/(<)(td|th)(?=\h|>)/i ' , $ this ->template ['heading_cell_start ' ], $ valueHead );
299- $ strHeading = count ($ valueHead ) === 3 ? $ valueHead [1 ] . $ valueHead [2 ] : null ;
298+ $ headerTag = null ;
299+
300+ if (preg_match ('/(<)(td|th)(?=\h|>)/i ' , $ this ->template ['heading_cell_start ' ], $ matches ) === 1 ) {
301+ $ headerTag = $ matches [0 ];
302+ }
300303
301304 $ out .= $ this ->template ['thead_open ' ] . $ this ->newline . $ this ->template ['heading_row_start ' ] . $ this ->newline ;
302305
303306 foreach ($ this ->heading as $ heading ) {
304307 $ temp = $ this ->template ['heading_cell_start ' ];
305308
306309 foreach ($ heading as $ key => $ val ) {
307- if ($ key !== 'data ' && $ strHeading !== null ) {
308- $ temp = str_replace ($ strHeading , $ strHeading . ' ' . $ key . '=" ' . $ val . '" ' , $ temp );
310+ if ($ key !== 'data ' && $ headerTag !== null ) {
311+ $ temp = str_replace ($ headerTag , $ headerTag . ' ' . $ key . '=" ' . $ val . '" ' , $ temp );
309312 }
310313 }
311314
@@ -358,18 +361,20 @@ public function generate($tableData = null)
358361
359362 // Any table footing to display?
360363 if (! empty ($ this ->footing )) {
361- // Check if there is a th or td tag, null if not
362- preg_match ('/(<)(td|th)(?=\h|>)/i ' , $ this ->template ['footing_cell_start ' ], $ valueFoot );
363- $ strFooting = count ($ valueFoot ) === 3 ? $ valueFoot [1 ] . $ valueFoot [2 ] : null ;
364+ $ footerTag = null ;
365+
366+ if (preg_match ('/(<)(td|th)(?=\h|>)/i ' , $ this ->template ['footing_cell_start ' ], $ matches )) {
367+ $ footerTag = $ matches [0 ];
368+ }
364369
365370 $ out .= $ this ->template ['tfoot_open ' ] . $ this ->newline . $ this ->template ['footing_row_start ' ] . $ this ->newline ;
366371
367372 foreach ($ this ->footing as $ footing ) {
368373 $ temp = $ this ->template ['footing_cell_start ' ];
369374
370375 foreach ($ footing as $ key => $ val ) {
371- if ($ key !== 'data ' && $ strFooting !== null ) {
372- $ temp = str_replace ($ strFooting , $ strFooting . ' ' . $ key . '=" ' . $ val . '" ' , $ temp );
376+ if ($ key !== 'data ' && $ footerTag !== null ) {
377+ $ temp = str_replace ($ footerTag , $ footerTag . ' ' . $ key . '=" ' . $ val . '" ' , $ temp );
373378 }
374379 }
375380
0 commit comments