Code Duplication    Length = 29-30 lines in 2 locations

class/Utility.php 1 location

@@ 1422-1451 (lines=30) @@
1419
     * @param $string
1420
     * @return string
1421
     */
1422
public static function closeTags($string)
1423
{
1424
    // match opened tags
1425
        if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
1426
            $start_tags = $start_tags[1];
1427
            // match closed tags
1428
            if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
1429
                $complete_tags = [];
1430
                $end_tags      = $end_tags[1];
1431
1432
                foreach ($start_tags as $key => $val) {
1433
                    $posb = array_search($val, $end_tags);
1434
                    if (is_int($posb)) {
1435
                        unset($end_tags[$posb]);
1436
                    } else {
1437
                        $complete_tags[] = $val;
1438
                    }
1439
                }
1440
            } else {
1441
                $complete_tags = $start_tags;
1442
            }
1443
1444
            $complete_tags = array_reverse($complete_tags);
1445
            for ($i = 0, $iMax = count($complete_tags); $i < $iMax; ++$i) {
1446
                $string .= '</' . $complete_tags[$i] . '>';
1447
            }
1448
        }
1449
1450
    return $string;
1451
}
1452
1453
    /**
1454
     * Smarty plugin

include/functions.php 1 location

@@ 987-1015 (lines=29) @@
984
 * @author   Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson
985
 *           <amos dot robinson at gmail dot com>
986
 */
987
function lx_close_tags($string) {
988
    // match opened tags
989
    if(preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
990
        $start_tags = $start_tags[1];
991
        // match closed tags
992
        if(preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
993
            $complete_tags = array();
994
            $end_tags = $end_tags[1];
995
    
996
            foreach($start_tags as $key => $val) {
997
                $posb = array_search($val, $end_tags);
998
                   if(is_integer($posb)) {
999
                      unset($end_tags[$posb]);
1000
                   } else {
1001
                    $complete_tags[] = $val;
1002
                }
1003
            }
1004
        } else {
1005
            $complete_tags = $start_tags;
1006
        }
1007
        
1008
        $complete_tags = array_reverse($complete_tags);
1009
        for($i = 0; $i < count($complete_tags); $i++) {
1010
            $string .= '</' . $complete_tags[$i] . '>';
1011
        }
1012
    }
1013
1014
    return $string;
1015
}
1016
1017
/**
1018
 * Smarty plugin