Skip to content

Commit a447d74

Browse files
committed
fix: move preg_match only once
1 parent cd8d388 commit a447d74

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

‎system/View/Table.php‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,14 @@ public function generate($tableData = null)
295295

296296
// Is there a table heading to display?
297297
if (! empty($this->heading)) {
298+
preg_match('/(<)(td|th)/i', $this->template['heading_cell_start'], $valueHead);
299+
$strHeading = count($valueHead) === 3 ? $valueHead[1] . $valueHead[2] : null;
300+
298301
$out .= $this->template['thead_open'] . $this->newline . $this->template['heading_row_start'] . $this->newline;
299302

300303
foreach ($this->heading as $heading) {
301304
$temp = $this->template['heading_cell_start'];
302305

303-
// Check tag with td or th
304-
// If not will return null
305-
preg_match('/(<)(td|th)/i', $temp, $valueHead);
306-
$strHeading = count($valueHead) === 3 ? $valueHead[1] . $valueHead[2] : null;
307-
308306
foreach ($heading as $key => $val) {
309307
if ($key !== 'data') {
310308
$temp = $strHeading ? str_replace($strHeading, $strHeading . ' ' . $key . '="' . $val . '"', $temp) : $temp;
@@ -360,16 +358,15 @@ public function generate($tableData = null)
360358

361359
// Any table footing to display?
362360
if (! empty($this->footing)) {
361+
// Check if there is a th or td tag, null if not
362+
preg_match('/(<)(td|th)/i', $this->template['footing_cell_start'], $valueFoot);
363+
$strFooting = count($valueFoot) === 3 ? $valueFoot[1] . $valueFoot[2] : null;
364+
363365
$out .= $this->template['tfoot_open'] . $this->newline . $this->template['footing_row_start'] . $this->newline;
364366

365367
foreach ($this->footing as $footing) {
366368
$temp = $this->template['footing_cell_start'];
367369

368-
// Check tag with td or th
369-
// If not will return null
370-
preg_match('/(<)(td|th)/i', $temp, $valueFoot);
371-
$strFooting = count($valueFoot) === 3 ? $valueFoot[1] . $valueFoot[2] : null;
372-
373370
foreach ($footing as $key => $val) {
374371
if ($key !== 'data') {
375372
$temp = $strFooting ? str_replace($strFooting, $strFooting . ' ' . $key . '="' . $val . '"', $temp) : $temp;

0 commit comments

Comments
 (0)