7 |
return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾"); |
return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾"); |
8 |
} |
} |
9 |
|
|
10 |
|
function Letters() { return "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; } |
11 |
|
|
12 |
function Slova($alpha_only = false) { |
function Slova($alpha_only = false) { |
13 |
$sl = array("A", "B", "C", "È", "Æ", "D", "Ð", "E", "F", |
$sl = preg_split('//', Letters()); |
14 |
"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", |
array_pop($sl); // The final element is empty. |
|
"R", "S", "©", "T", "U", "V", "W", "X", "Y", "Z", "®"); |
|
15 |
if (!$alpha_only) array_unshift($sl, "@"); |
if (!$alpha_only) array_unshift($sl, "@"); |
16 |
return $sl; |
return $sl; |
17 |
} |
} |
18 |
|
|
19 |
function MyCompare($a, $b) { |
function MyCompare($a, $b) { |
20 |
$slova = "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; |
$slova = Letters(); |
21 |
$weights = "\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32"; |
$weights = "\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32"; |
22 |
return strcasecmp(strtr(MyUpper($a), $slova, $weights), |
return strcasecmp(strtr(MyUpper($a), $slova, $weights), |
23 |
strtr(MyUpper($b), $slova, $weights)); |
strtr(MyUpper($b), $slova, $weights)); |
24 |
} |
} |
25 |
|
|
26 |
function MyEscape($str) { |
function my_replace($str, $start, $end, $pat = "", $rep = "") { |
27 |
$allowed = array("", "B", "I", "U", "UL", "OL", "LI"); |
if (!$pat) $pat = '\s*(\r\n?|\n\r?)'; |
28 |
$str = preg_replace("/(\<\/?\s*(\w+)>[^\>]*\>)/e", |
$idx1 = $idx2 = -1; |
29 |
"array_search(MyUpper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')", |
while (true) { |
30 |
$str); |
$str2 = strtoupper($str); |
31 |
$str = preg_replace("/(^\s+|\s+$)/", "", $str); |
$idx1 = strpos($str2, $start, $idx1 + 1); |
32 |
$str = ereg_replace("\"", """, $str); |
if ($idx1 === false) break; |
33 |
|
$idx2 = strpos($str2, $end, $idx2 + 1); |
34 |
|
if ($idx2 === false) break; |
35 |
|
if ($idx1 > $idx2) break; |
36 |
|
$idx2 += strlen($end); |
37 |
|
$str1 = substr($str, 0, $idx1); |
38 |
|
$str2 = preg_replace('/'.$pat.'/m', $rep, |
39 |
|
substr($str, $idx1, $idx2 - $idx1)); |
40 |
|
$str3 = substr($str, $idx2, strlen($str) - $idx2); |
41 |
|
$str = $str1.$str2.$str3; |
42 |
|
} |
43 |
|
return $str; |
44 |
|
} |
45 |
|
|
46 |
|
function MyEscape($str, $full = true) { |
47 |
|
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD"); |
48 |
|
$str = preg_replace("/(^\\s+|\\s+$)/", "", $str); |
49 |
|
$str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. |
50 |
|
'\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); |
51 |
|
$str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str); |
52 |
|
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
53 |
|
$str = my_replace($str, "<TABLE", "/TABLE>"); |
54 |
|
$str = my_replace($str, "<UL", "/UL>", true); |
55 |
|
$str = my_replace($str, "<OL", "/OL>"); |
56 |
|
if (!$full) my_replace($str, "<", ">", '"', "'|'"); |
57 |
|
$str = str_replace('"', """, $str); |
58 |
|
if (!$full) $str = str_replace("'|'", '"', $str); |
59 |
return $str; |
return $str; |
60 |
} |
} |
61 |
|
|
62 |
function ParseNewline($str, $paragraphs = false) { |
function ParseNewline($str, $paragraphs = false) { |
63 |
if (!$str) return $str; |
if (!$str) return $str; |
64 |
if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', ' </p><p class="ptext">', $str); |
if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', ' </p><p class="ptext">', $str); |
65 |
$str = ereg_replace("[ \t]*(\r\n?|\n\r?)", '<br>', $str); |
return nl2br($str); |
|
return $str; |
|
66 |
} |
} |
67 |
|
|
68 |
function error($msg) { |
function error($msg) { |
90 |
); |
); |
91 |
$t = intval($str); |
$t = intval($str); |
92 |
# Skip if not a scalar |
# Skip if not a scalar |
93 |
if (!is_scalar($str)) return $str; |
if (!is_string($str)) return $str; |
94 |
# If a number, don't touch it |
# If a number, don't touch it |
95 |
if (strcmp(intval($str), $str) == 0) return $str; |
if (strcmp(intval($str), $str) == 0) return $str; |
96 |
# Replace "<BR>" with "\n" |
# Replace "<BR>" with "\n" |
101 |
$str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str); |
$str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str); |
102 |
# Remove "<HEAD>"/"</HEAD>", and anything in between. |
# Remove "<HEAD>"/"</HEAD>", and anything in between. |
103 |
$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); |
104 |
# Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<P>" and "BR" tags, along with their pairs |
# Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>", |
105 |
|
# "<P>" and "<BR>" tags, along with their pairs |
106 |
$str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); |
$str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); |
107 |
|
# Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>") |
108 |
|
#$str = preg_replace("/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im", '', $str); |
109 |
|
# "<P>" and "<BR>" tags, along with their pairs |
110 |
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
111 |
$str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str); |
$str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str); |
112 |
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
113 |
$str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str); |
$str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str); |
114 |
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
115 |
$str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str); |
$str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str); |
116 |
# Replace "``" and "''" with """ (a single double quote) |
# Replace "``" and "''" with """ (normal ASCII double quote) |
117 |
$str = str_replace("“", '"', $str); |
$str = str_replace("“", '"', $str); |
118 |
$str = str_replace("”", '"', $str); |
$str = str_replace("”", '"', $str); |
119 |
# Replace "-" with "-" |
# Replace "-" with "-" |