1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| <?php
// function repairs a complete block of content
// input : content,
// output : repaired content
function za_repair_content($input)
{$ret = za_repair_attribute($input, 'class');
$ret = za_repair_attribute($ret, 'padding');
$ret = za_repair_attribute($ret, 'target');
$ret = za_repair_attribute($ret, 'colspan');
$ret = za_repair_attribute($ret, 'rowspan');
$ret = za_repair_attribute($ret, 'border');
$ret = za_repair_attribute($ret, 'cellspacing');
$ret = za_repair_attribute($ret, 'cellpadding');
$ret = za_repair_attribute($ret, 'color');
$ret = za_repair_attribute($ret, 'target');
$ret = za_repair_attribute($ret, 'width');
$ret = za_repair_attribute($ret, 'height');
$ret = za_repair_attribute($ret, 'value');
$ret = za_repair_attribute($ret, 'size');
$ret = za_repair_attribute($ret, 'maxwidth');
return $ret;
};
// function repairs a single tag type within a block of content
// input: content and attribute to be repaired
// output = repaired content
function za_repair_attribute($input, $attribute)
{$todo = $input;
$done ='';
while (strpos($todo, '<') !== false)
{$posstart=strpos($todo, '<');
$done=$done.substr($todo,0,$posstart+1);
$todo=substr($todo,$posstart+1,strlen($todo));
$posend=strpos($todo, '>');
if ($posend!==false)
{$tag=substr($todo,0, $posend);
$tag=za_repair_tag($tag, $attribute);
$todo=substr($todo,$posend+1,strlen($todo));
$done=$done.$tag.'>';
};
}
return $done.$todo;
};
// function repairs tags
// input: content of tag, attribute to be repaired
// output: repaired tag
function za_repair_tag($input, $attribute)
{$ret = "";
$pos=strpos(strtoupper($input), strtoupper($attribute));
if ($pos===false)
{$ret=$input;}
else
{if (substr($input, $pos+strlen($attribute),1)=="=" && substr($input, $pos+strlen($attribute)+1,1)!="\"" && substr($input, $pos+strlen($attribute)+1,1)!='"')
{$done=substr($input, 0, $pos+strlen($attribute)+1).'"';
$todo=substr($input, $pos+strlen($attribute)+1);
$pos=strpos($todo,' ');
if ($pos===false)
{$ret=$done.$todo.'"';}
else
{$ret=$done.substr($todo,0,$pos).'"'.substr($todo, $pos);};
}
else
{$ret=$input;};
}
return $ret;
};
?> |