1 |
<?php |
<?php |
2 |
|
|
3 |
function MyUpper($str) { |
function MyUpper($str) { |
4 |
return strtr(strtoupper($str), "", "Ʈ"); |
return strtr(strtoupper($str), "", "Ʈ"); |
5 |
} |
} |
12 |
|
|
13 |
function Slova($alpha_only = false) { |
function Slova($alpha_only = false) { |
14 |
$sl = preg_split('//', Letters()); |
$sl = preg_split('//', Letters()); |
15 |
array_pop($sl); // The final element is empty. |
array_shift($sl); // First element is empty. |
16 |
|
array_pop($sl); // Last element is empty. |
17 |
if (!$alpha_only) array_unshift($sl, "@"); |
if (!$alpha_only) array_unshift($sl, "@"); |
18 |
return $sl; |
return $sl; |
19 |
} |
} |
45 |
return $str; |
return $str; |
46 |
} |
} |
47 |
|
|
48 |
function MyEscape($str, $full = true) { |
function MyEscape($str, $full = false) { |
49 |
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD"); |
if ($full) { |
50 |
$str = preg_replace("/(^\\s+|\\s+$)/", "", $str); |
$str = str_replace("&", "&", $str); |
51 |
|
$str = str_replace("<", "<", $str); |
52 |
|
$str = str_replace(">", ">", $str); |
53 |
|
} |
54 |
|
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD", "HR", "SUP", "SUB"); |
55 |
|
$str = preg_replace('/(^[ ]+|[ ]+$)/m', '', $str); |
56 |
$str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. |
$str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. |
57 |
'\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); |
'\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); |
58 |
$str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str); |
$str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str); |
59 |
|
$str = preg_replace('/(target=_blank class=[^ ]+)( target=_blank class=[^ ]+)+/', '\\1', $str); |
60 |
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
61 |
|
$str = preg_replace('/(class=[^ ]+)( class=[^ ]+)+/', '\\1', $str); |
62 |
$str = my_replace($str, "<TABLE", "/TABLE>"); |
$str = my_replace($str, "<TABLE", "/TABLE>"); |
63 |
$str = my_replace($str, "<UL", "/UL>", true); |
$str = my_replace($str, "<UL", "/UL>", true); |
64 |
$str = my_replace($str, "<OL", "/OL>"); |
$str = my_replace($str, "<OL", "/OL>"); |
65 |
if (!$full) my_replace($str, "<", ">", '"', "'|'"); |
if (!$full) $str = my_replace($str, "<", ">", '"', "'|'"); |
66 |
$str = str_replace('"', """, $str); |
$str = str_replace('"', """, $str); |
67 |
if (!$full) $str = str_replace("'|'", '"', $str); |
if (!$full) $str = str_replace("'|'", '"', $str); |
68 |
return $str; |
return $str; |
70 |
|
|
71 |
function ParseNewline($str, $paragraphs = false) { |
function ParseNewline($str, $paragraphs = false) { |
72 |
if (!$str) return $str; |
if (!$str) return $str; |
73 |
if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', ' </p><p class="ptext">', $str); |
$str = str_replace("\r\n", "\n", $str); |
74 |
return nl2br($str); |
if ($paragraphs) $str = preg_replace('/[ ]*\n\n/s', ' </p><p class="ptext">', $str); |
75 |
|
$str = preg_replace('/[ ]*\n/s', '<br>'."\n", $str); |
76 |
|
return $str; |
77 |
} |
} |
78 |
|
|
79 |
function error($msg) { |
function error($msg) { |
91 |
"Scaron" => "", "#352" => "", |
"Scaron" => "", "#352" => "", |
92 |
"scaron" => "", "#353" => "", |
"scaron" => "", "#353" => "", |
93 |
"Ccaron" => "", "#268" => "", "#268" => "", |
"Ccaron" => "", "#268" => "", "#268" => "", |
94 |
"ccaron" => "", "#232" => "", "#269" => "", |
"ccaron" => "", "egrave" => "", "#232" => "", "#269" => "", |
95 |
"Cgrave" => "", "#262" => "", "#" => "", |
"Cgrave" => "", "#262" => "", "#" => "", |
96 |
"cgrave" => "", "#230" => "", "#263" => "", |
"cgrave" => "", "aelig" => "", "#230" => "", "#263" => "", |
97 |
"???" => "", "#272" => "", "#" => "", |
"<?>" => "", "#272" => "", "#" => "", |
98 |
"???" => "", "#273" => "", |
"<?>" => "", "eth" => "", "#273" => "", |
99 |
"Zcaron" => "", "#381" => "", |
"Zcaron" => "", "#381" => "", |
100 |
"zcaron" => "", "#382" => "", |
"zcaron" => "", "#382" => "", |
101 |
); |
); |
|
$t = intval($str); |
|
102 |
# Skip if not a scalar |
# Skip if not a scalar |
103 |
if (!is_string($str)) return $str; |
if (!is_string($str)) return $str; |
104 |
# If a number, don't touch it |
# If a number, don't touch it |
105 |
if (strcmp(intval($str), $str) == 0) return $str; |
if (strcmp(intval($str)."", $str."") == 0) return $str; |
106 |
|
|
107 |
|
# Replace "``", "''", "<<" and ">>" with """ (normal ASCII double quote) |
108 |
|
$str = str_replace("", '"', $str); |
109 |
|
$str = str_replace("", '"', $str); |
110 |
|
$str = str_replace("", '"', $str); |
111 |
|
$str = str_replace("", '"', $str); |
112 |
|
# Replace "-" with "-" |
113 |
|
$str = str_replace("", '-', $str); |
114 |
|
# Replace character references ("&...;" and "&#...;") with its value |
115 |
|
$str = preg_replace('/\&([^;]+);/em', '$entities["$1"]?$entities["$1"]:"?"', $str); |
116 |
|
# Remove all whitespace from line beginnings and endings |
117 |
|
$str = preg_replace('/(^[ ]+|[ ]+$)/s', '', $str); |
118 |
|
# Remove "<P>[whitespace]</P>" |
119 |
|
$str = preg_replace('/\<\s*P[^\>]*\>\s*\<\/\s*P\s*\>/im', "", $str); |
120 |
|
# Replace "<BR>\n" with "\n" |
121 |
|
$str = preg_replace('/\<[ ]*BR[^\>]*\>([\n\r]+)/im', '$1', $str); |
122 |
|
# Replace "<P>" with "\n" |
123 |
|
$str = preg_replace('/\<\s*P[^\>]*\>/im', "", $str); |
124 |
|
# Replace "</P>" with "\n" |
125 |
|
$str = preg_replace('/\<\/\s*P[^\>]*\>/im', "\n", $str); |
126 |
# Replace "<BR>" with "\n" |
# Replace "<BR>" with "\n" |
127 |
$str = preg_replace("/\<BR\>/m", "\n", $str); |
$str = preg_replace('/\<BR\>/im', "\n", $str); |
128 |
# Replace "<...>\n" with "<...>" |
# Replace "<...>\n" with "\n<...>" |
129 |
$str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str); |
$str = preg_replace('/(\<[^\/][^\>]*\>)[ ]*([\r\n]*)[ ]*/m', '$2$1', $str); |
130 |
# Replace "\n</...>" with "</...>\n" |
# Replace "\n</...>" with "</...>\n" |
131 |
$str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str); |
$str = preg_replace('/[ ]*([\n\r]*)[ ]*(\<\/[^\>]+\>)/m', '$2$1', $str); |
132 |
# Remove "<HEAD>"/"</HEAD>", and anything in between. |
# Remove "<HEAD>" and "</HEAD>", and anything in between. |
133 |
$str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str); |
$str = preg_replace('/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims', '', $str); |
134 |
# Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>", |
# Remove all "<HTML>", "<HEAD>", "<BODY>" and "<FONT>" tags, along with their pairs |
135 |
# "<P>" and "<BR>" tags, along with their pairs |
$str = preg_replace('/\<\/?\s*(HTML|HEAD|BODY|FONT|DIR)[^\>]*\>/im', '', $str); |
|
$str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); |
|
136 |
# Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>") |
# Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>") |
137 |
#$str = preg_replace("/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im", '', $str); |
#$str = preg_replace('/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im', '', $str); |
|
# "<P>" and "<BR>" tags, along with their pairs |
|
138 |
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
139 |
$str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str); |
$str = preg_replace('/([ ]*[\r\n]*)(\<\/?\s*(LI|UL|OL)[ ]*\>)([ ]*[\r\n]*)/m', '$2', $str); |
140 |
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
141 |
$str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str); |
$str = preg_replace('/(\<\s*(UL|OL)\s*\>)([ ]*(\r\n?|\n\r?))+/m', '$1', $str); |
142 |
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
143 |
$str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str); |
$str = preg_replace('/([ ]*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m', '$3', $str); |
144 |
# Replace "``" and "''" with """ (normal ASCII double quote) |
# Replace "<[whitespace]/>" with "</" |
145 |
$str = str_replace("", '"', $str); |
$str = preg_replace('/\<\s*\//', '</', $str); |
146 |
$str = str_replace("", '"', $str); |
# Do some wild exchanges... |
147 |
# Replace "-" with "-" |
$str = preg_replace('/(\<[ ]*(B|U|I)[^\>]*\>)[ ]*(\<\/[ ]*(UL|OL|LI)[^\>]*\>)/', '$3$1', $str); |
148 |
$str = str_replace("", '-', $str); |
$str = preg_replace('/(\<[ ]*(UL|OL|LI)[^\>]*\>)[ ]*(\<\/[ ]*(B|U|I)[^\>]*\>)/', '$3$1', $str); |
|
# Replace character references ("&...;" and "&#...;") with its value |
|
|
$str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str); |
|
|
# Remove all whitespace at beginning or ending of a line |
|
|
$str = preg_replace("/(^\s+|\s+$)/", '', $str); |
|
149 |
# Convert Win1250 to ISO8859-2 |
# Convert Win1250 to ISO8859-2 |
150 |
|
# (Actually, it should already be in ISO8859-2, but you never know.) |
151 |
$str = strtr($str, "Ǝ", "Ʈ"); |
$str = strtr($str, "Ǝ", "Ʈ"); |
152 |
return $str; |
return $str; |
153 |
} |
} |
154 |
|
|
155 |
?> |
?> |