Code Duplication    Length = 29-30 lines in 2 locations

class/Utility.php 1 location

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

include/functions.php 1 location

@@ 835-863 (lines=29) @@
832
 * @author   Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson
833
 *           <amos dot robinson at gmail dot com>
834
 */
835
function lx_close_tags($string) {
836
    // match opened tags
837
    if(preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
838
        $start_tags = $start_tags[1];
839
        // match closed tags
840
        if(preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
841
            $complete_tags = array();
842
            $end_tags = $end_tags[1];
843
    
844
            foreach($start_tags as $key => $val) {
845
                $posb = array_search($val, $end_tags);
846
                   if(is_integer($posb)) {
847
                      unset($end_tags[$posb]);
848
                   } else {
849
                    $complete_tags[] = $val;
850
                }
851
            }
852
        } else {
853
            $complete_tags = $start_tags;
854
        }
855
        
856
        $complete_tags = array_reverse($complete_tags);
857
        for($i = 0; $i < count($complete_tags); $i++) {
858
            $string .= '</' . $complete_tags[$i] . '>';
859
        }
860
    }
861
862
    return $string;
863
}
864
865
/**
866
 * Smarty plugin