Code Duplication    Length = 29-30 lines in 2 locations

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

class/Utility.php 1 location

@@ 1442-1471 (lines=30) @@
1439
     * @param $string
1440
     * @return string
1441
     */
1442
public static function closeTags($string)
1443
{
1444
    // match opened tags
1445
        if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
1446
            $start_tags = $start_tags[1];
1447
            // match closed tags
1448
            if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
1449
                $complete_tags = [];
1450
                $end_tags      = $end_tags[1];
1451
1452
                foreach ($start_tags as $key => $val) {
1453
                    $posb = array_search($val, $end_tags);
1454
                    if (is_int($posb)) {
1455
                        unset($end_tags[$posb]);
1456
                    } else {
1457
                        $complete_tags[] = $val;
1458
                    }
1459
                }
1460
            } else {
1461
                $complete_tags = $start_tags;
1462
            }
1463
1464
            $complete_tags = array_reverse($complete_tags);
1465
            for ($i = 0, $iMax = count($complete_tags); $i < $iMax; ++$i) {
1466
                $string .= '</' . $complete_tags[$i] . '>';
1467
            }
1468
        }
1469
1470
    return $string;
1471
}
1472
1473
    /**
1474
     * Smarty plugin