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 |
} |
} |
46 |
} |
} |
47 |
|
|
48 |
function MyEscape($str, $full = true) { |
function MyEscape($str, $full = true) { |
49 |
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD"); |
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD", "HR"); |
50 |
$str = preg_replace("/(^\\s+|\\s+$)/", "", $str); |
$str = preg_replace('/(^\s+|\s+$)/m', '', $str); |
51 |
$str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. |
$str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. |
52 |
'\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); |
'\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); |
53 |
$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); |
54 |
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
55 |
|
$str = preg_replace('/(class=normal)( class=normal)+/', '\\1', $str); |
56 |
$str = my_replace($str, "<TABLE", "/TABLE>"); |
$str = my_replace($str, "<TABLE", "/TABLE>"); |
57 |
$str = my_replace($str, "<UL", "/UL>", true); |
$str = my_replace($str, "<UL", "/UL>", true); |
58 |
$str = my_replace($str, "<OL", "/OL>"); |
$str = my_replace($str, "<OL", "/OL>"); |
59 |
if (!$full) my_replace($str, "<", ">", '"', "'|'"); |
if (!$full) $str = my_replace($str, "<", ">", '"', "'|'"); |
60 |
$str = str_replace('"', """, $str); |
$str = str_replace('"', """, $str); |
61 |
if (!$full) $str = str_replace("'|'", '"', $str); |
if (!$full) $str = str_replace("'|'", '"', $str); |
62 |
return $str; |
return $str; |
64 |
|
|
65 |
function ParseNewline($str, $paragraphs = false) { |
function ParseNewline($str, $paragraphs = false) { |
66 |
if (!$str) return $str; |
if (!$str) return $str; |
67 |
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); |
68 |
return nl2br($str); |
if ($paragraphs) $str = preg_replace('/[ ]*\n\n/s', ' </p><p class="ptext">', $str); |
69 |
|
$str = preg_replace('/[ ]*\n/s', '<br>'."\n", $str); |
70 |
|
return $str; |
71 |
} |
} |
72 |
|
|
73 |
function error($msg) { |
function error($msg) { |
85 |
"Scaron" => "©", "#352" => "©", |
"Scaron" => "©", "#352" => "©", |
86 |
"scaron" => "¹", "#353" => "¹", |
"scaron" => "¹", "#353" => "¹", |
87 |
"Ccaron" => "È", "#268" => "È", "#268" => "È", |
"Ccaron" => "È", "#268" => "È", "#268" => "È", |
88 |
"ccaron" => "è", "#232" => "è", "#269" => "è", |
"ccaron" => "è", "egrave" => "è", "#232" => "è", "#269" => "è", |
89 |
"Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ", |
"Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ", |
90 |
"cgrave" => "æ", "#230" => "æ", "#263" => "æ", |
"cgrave" => "æ", "aelig" => "æ", "#230" => "æ", "#263" => "æ", |
91 |
"???" => "Ð", "#272" => "Ð", "#" => "Ð", |
"<?>" => "Ð", "#272" => "Ð", "#" => "Ð", |
92 |
"???" => "ð", "#273" => "ð", |
"<?>" => "ð", "eth" => "ð", "#273" => "ð", |
93 |
"Zcaron" => "®", "#381" => "®", |
"Zcaron" => "®", "#381" => "®", |
94 |
"zcaron" => "¾", "#382" => "¾", |
"zcaron" => "¾", "#382" => "¾", |
95 |
); |
); |
|
$t = intval($str); |
|
96 |
# Skip if not a scalar |
# Skip if not a scalar |
97 |
if (!is_string($str)) return $str; |
if (!is_string($str)) return $str; |
98 |
# If a number, don't touch it |
# If a number, don't touch it |
99 |
if (strcmp(intval($str), $str) == 0) return $str; |
if (strcmp(intval($str)."", $str."") == 0) return $str; |
100 |
# Replace "<BR>" with "\n" |
|
|
$str = preg_replace("/\<BR\>/m", "\n", $str); |
|
|
# Replace "<...>\n" with "<...>" |
|
|
$str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str); |
|
|
# Replace "\n</...>" with "</...>\n" |
|
|
$str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str); |
|
|
# Remove "<HEAD>"/"</HEAD>", and anything in between. |
|
|
$str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str); |
|
|
# Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>", |
|
|
# "<P>" and "<BR>" tags, along with their pairs |
|
|
$str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); |
|
|
# Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>") |
|
|
#$str = preg_replace("/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im", '', $str); |
|
|
# "<P>" and "<BR>" tags, along with their pairs |
|
|
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
|
|
$str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str); |
|
|
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
|
|
$str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str); |
|
|
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
|
|
$str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str); |
|
101 |
# Replace "``" and "''" with """ (normal ASCII double quote) |
# Replace "``" and "''" with """ (normal ASCII double quote) |
102 |
$str = str_replace("“", '"', $str); |
$str = str_replace("“", '"', $str); |
103 |
$str = str_replace("”", '"', $str); |
$str = str_replace("”", '"', $str); |
104 |
# Replace "-" with "-" |
# Replace "-" with "-" |
105 |
$str = str_replace("—", '-', $str); |
$str = str_replace("—", '-', $str); |
106 |
# Replace character references ("&...;" and "&#...;") with its value |
# Replace character references ("&...;" and "&#...;") with its value |
107 |
$str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str); |
$str = preg_replace('/\&([^;]+);/em', '$entities["$1"]?$entities["$1"]:"?"', $str); |
108 |
# Remove all whitespace at beginning or ending of a line |
# Remove all whitespace from line beginnings and endings |
109 |
$str = preg_replace("/(^\s+|\s+$)/", '', $str); |
$str = preg_replace('/(^[ ]+|[ ]+$)/s', '', $str); |
110 |
|
# Remove "<P>[whitespace]</P>" |
111 |
|
$str = preg_replace('/\<\s*P[^\>]*\>\s*\<\/\s*P\s*\>/im', "", $str); |
112 |
|
# Replace "<BR>\n" with "\n" |
113 |
|
$str = preg_replace('/\<[ ]*BR[^\>]*\>([\n\r]+)/im', '$1', $str); |
114 |
|
# Replace "<P>" with "\n" |
115 |
|
$str = preg_replace('/\<\s*P[^\>]*\>/im', "", $str); |
116 |
|
# Replace "</P>" with "\n" |
117 |
|
$str = preg_replace('/\<\/\s*P[^\>]*\>/im', "\n", $str); |
118 |
|
# Replace "<BR>" with "\n" |
119 |
|
$str = preg_replace('/\<BR\>/im', "\n", $str); |
120 |
|
# Replace "<...>\n" with "\n<...>" |
121 |
|
$str = preg_replace('/(\<[^\/][^\>]*\>)[ ]*([\r\n]*)[ ]*/m', '$2$1', $str); |
122 |
|
# Replace "\n</...>" with "</...>\n" |
123 |
|
$str = preg_replace('/[ ]*([\n\r]*)[ ]*(\<\/[^\>]+\>)/m', '$2$1', $str); |
124 |
|
# Remove "<HEAD>" and "</HEAD>", and anything in between. |
125 |
|
$str = preg_replace('/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims', '', $str); |
126 |
|
# Remove all "<HTML>", "<HEAD>", "<BODY>" and "<FONT>" tags, along with their pairs |
127 |
|
$str = preg_replace('/\<\/?\s*(HTML|HEAD|BODY|FONT|DIR)[^\>]*\>/im', '', $str); |
128 |
|
# Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>") |
129 |
|
#$str = preg_replace('/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im', '', $str); |
130 |
|
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
131 |
|
$str = preg_replace('/([ ]*[\r\n]*)(\<\/?\s*(LI|UL|OL)[ ]*\>)([ ]*[\r\n]*)/m', '$2', $str); |
132 |
|
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
133 |
|
$str = preg_replace('/(\<\s*(UL|OL)\s*\>)([ ]*(\r\n?|\n\r?))+/m', '$1', $str); |
134 |
|
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
135 |
|
$str = preg_replace('/([ ]*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m', '$3', $str); |
136 |
|
# Replace "<[whitespace]/>" with "</" |
137 |
|
$str = preg_replace('/\<\s*\//', '</', $str); |
138 |
|
# Do some wild exchanges... |
139 |
|
$str = preg_replace('/(\<[ ]*(B|U|I)[^\>]*\>)[ ]*(\<\/[ ]*(UL|OL|LI)[^\>]*\>)/', '$3$1', $str); |
140 |
|
$str = preg_replace('/(\<[ ]*(UL|OL|LI)[^\>]*\>)[ ]*(\<\/[ ]*(B|U|I)[^\>]*\>)/', '$3$1', $str); |
141 |
# Convert Win1250 to ISO8859-2 |
# Convert Win1250 to ISO8859-2 |
142 |
|
# (Actually, it should already be in ISO8859-2, but you never know.) |
143 |
$str = strtr($str, "ŠÐÈÆŽšðèæž", "©ÐÈÆ®¹ðèæ¾"); |
$str = strtr($str, "ŠÐÈÆŽšðèæž", "©ÐÈÆ®¹ðèæ¾"); |
144 |
return $str; |
return $str; |
145 |
} |
} |
146 |
|
|
147 |
?> |
?> |