Kod
<B>Witam! Zapraszam na moją stronę o <U>grach, jest ona <I>najlepsza!</I>
To funkcja powinna zwrócić:
Kod
<B>Witam! Zapraszam na moją stronę o </B><U>grach, jest ona </U><I>najlepsza!</I>
Liczy się, aby było to zgodne z W3C.
Prezentuję poniżej kod mojej funkcji i mam nadzieję, że komuś z Was przyjdzie do głowy jak naprawić ten problem.
function repair_html($str) { # Define arrays # Count opened tags foreach($tags_open as $id => $tag) { $count=$count_big+$count_small; $tags_open_num[$id]=$count; } # Count closed tags foreach($tags_close as $id => $tag) { $count=$count_big+$count_small; $tags_close_num[$id]=$count; } # Count opened but not closed tags foreach($tags_open as $id => $tag) { $no_closed=$tags_open_num[$id]-$tags_close_num[$id]; $tags_status[$id]=$no_closed; } # Close not closed tags foreach($tags_open as $id => $tag) { $status=$tags_status[$id]; if($status>0) { $opened_num=$tags_open_num[$id]; $close_tag=$tags_close[$id]; for($i=$status;$i<=$opened_num;$i++) { $str.=$close_tag; } } } return $str; } $html='<b>Witam! Co tam u ciebie? Ja <i> nic nie robię!'; $html_new=repair_html($html);
Pozdrawiam,
ladovnik
PS To "echo '<b>Status tagu..." itp. jest tylko do testów i wykrywania błędów.