| @@ 956-981 (lines=26) @@ | ||
| 953 | * @return string |
|
| 954 | * @author Milian Wolff <mail -at- milianw.de> |
|
| 955 | */ |
|
| 956 | function lx_closetags2($html){ |
|
| 957 | // put all opened tags into an array |
|
| 958 | preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result); |
|
| 959 | $openedtags=$result[1]; |
|
| 960 | ||
| 961 | // put all closed tags into an array |
|
| 962 | preg_match_all("#</([a-z]+)>#iU",$html,$result); |
|
| 963 | $closedtags=$result[1]; |
|
| 964 | $len_opened = count($openedtags); |
|
| 965 | // all tags are closed |
|
| 966 | if(count($closedtags) == $len_opened){ |
|
| 967 | return $html; |
|
| 968 | } |
|
| 969 | ||
| 970 | $openedtags = array_reverse($openedtags); |
|
| 971 | // close tags |
|
| 972 | for($i=0;$i < $len_opened;$i++) { |
|
| 973 | if (!in_array($openedtags[$i],$closedtags)){ |
|
| 974 | $html .= '</'.$openedtags[$i].'>'; |
|
| 975 | } else { |
|
| 976 | unset($closedtags[array_search($openedtags[$i],$closedtags)]); |
|
| 977 | } |
|
| 978 | } |
|
| 979 | ||
| 980 | return $html; |
|
| 981 | } |
|
| 982 | ||
| 983 | /** |
|
| 984 | * @author Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson |
|
| @@ 1408-1434 (lines=27) @@ | ||
| 1405 | * @return string |
|
| 1406 | * @author Milian Wolff <mail -at- milianw.de> |
|
| 1407 | */ |
|
| 1408 | public static function closeTags2($html) |
|
| 1409 | { |
|
| 1410 | // put all opened tags into an array |
|
| 1411 | preg_match_all('#<([a-z]+)( .*)?(?!/)>#iU', $html, $result); |
|
| 1412 | $openedtags = $result[1]; |
|
| 1413 | ||
| 1414 | // put all closed tags into an array |
|
| 1415 | preg_match_all('#</([a-z]+)>#iU', $html, $result); |
|
| 1416 | $closedtags = $result[1]; |
|
| 1417 | $len_opened = count($openedtags); |
|
| 1418 | // all tags are closed |
|
| 1419 | if (count($closedtags) == $len_opened) { |
|
| 1420 | return $html; |
|
| 1421 | } |
|
| 1422 | ||
| 1423 | $openedtags = array_reverse($openedtags); |
|
| 1424 | // close tags |
|
| 1425 | for ($i = 0; $i < $len_opened; ++$i) { |
|
| 1426 | if (!in_array($openedtags[$i], $closedtags)) { |
|
| 1427 | $html .= '</' . $openedtags[$i] . '>'; |
|
| 1428 | } else { |
|
| 1429 | unset($closedtags[array_search($openedtags[$i], $closedtags)]); |
|
| 1430 | } |
|
| 1431 | } |
|
| 1432 | ||
| 1433 | return $html; |
|
| 1434 | } |
|
| 1435 | ||
| 1436 | /** |
|
| 1437 | * @author Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson |
|