23 |
strtr(MyUpper($b), $slova, $weights)); |
strtr(MyUpper($b), $slova, $weights)); |
24 |
} |
} |
25 |
|
|
26 |
function MyEscape($str) { |
function nonl($str, $start, $end, $log = false) { |
27 |
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI"); |
$idx1 = $idx2 = -1; |
28 |
|
while (true) { |
29 |
|
$idx1 = strpos(strtoupper($str), $start, $idx1 + 1); |
30 |
|
$idx2 = strpos(strtoupper($str), $end, $idx2 + 1); |
31 |
|
if ($idx1 === false) break; |
32 |
|
if ($idx2 === false) break; |
33 |
|
if ($idx1 > $idx2) break; |
34 |
|
$idx2 += strlen($end); |
35 |
|
$str = substr($str, 0, $idx1).preg_replace('/\s*(\r\n?|\n\r?)/m', '', |
36 |
|
substr($str, $idx1, $idx2 - $idx1)).substr($str, |
37 |
|
$idx2, strlen($str) - $idx2); |
38 |
|
if ($log) { |
39 |
|
echo "<BIG>[$idx1] [$idx2]</BIG><BR>\n"; |
40 |
|
echo "<BIG>1:</BIG> [".substr($str, 0, $idx1)."]<BR>\n"; |
41 |
|
echo "<BIG>2:</BIG> [".substr($str, $idx1, $idx2 - $idx1)."]<BR>\n"; |
42 |
|
echo "<BIG>3:</BIG> [".substr($str, $idx2, strlen($str) - $idx2)."]<BR>\n"; |
43 |
|
} |
44 |
|
} |
45 |
|
return $str; |
46 |
|
} |
47 |
|
|
48 |
|
function MyEscape($str, $full = true) { |
49 |
|
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD"); |
50 |
$str = preg_replace("/(^\\s+|\\s+$)/", "", $str); |
$str = preg_replace("/(^\\s+|\\s+$)/", "", $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*[aA]\\b)/", '\\1 target=_blank class=more', $str); |
$str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str); |
54 |
$str = ereg_replace("\"", """, $str); |
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
55 |
|
$str = nonl($str, "<TABLE", "/TABLE>"); |
56 |
|
$str = nonl($str, "<UL", "/UL>", true); |
57 |
|
$str = nonl($str, "<OL", "/OL>"); |
58 |
|
if (!$full) { |
59 |
|
$idx1 = $idx2 = -1; |
60 |
|
while (true) { |
61 |
|
$idx1 = strpos($str, "<", $idx1 + 1); |
62 |
|
$idx2 = strpos($str, ">", $idx2 + 1); |
63 |
|
if ($idx1 === false) break; |
64 |
|
if ($idx2 === false) break; |
65 |
|
if ($idx1 > $idx2) break; |
66 |
|
$str = substr($str, 0, $idx1).str_replace('"', "'|'", |
67 |
|
substr($str, $idx1, $idx2 - $idx1)).substr($str, |
68 |
|
$idx2, strlen($str) - $idx2); |
69 |
|
} |
70 |
|
} |
71 |
|
$str = str_replace('"', """, $str); |
72 |
|
if (!$full) $str = str_replace("'|'", '"', $str); |
73 |
return $str; |
return $str; |
74 |
} |
} |
75 |
|
|
76 |
function ParseNewline($str, $paragraphs = false) { |
function ParseNewline($str, $paragraphs = false) { |
77 |
if (!$str) return $str; |
if (!$str) return $str; |
78 |
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); |
79 |
$str = ereg_replace("[ \t]*(\r\n?|\n\r?)", '<br>', $str); |
return nl2br($str); |
|
return $str; |
|
80 |
} |
} |
81 |
|
|
82 |
function error($msg) { |
function error($msg) { |
104 |
); |
); |
105 |
$t = intval($str); |
$t = intval($str); |
106 |
# Skip if not a scalar |
# Skip if not a scalar |
107 |
if (!is_scalar($str)) return $str; |
if (!is_string($str)) return $str; |
108 |
# If a number, don't touch it |
# If a number, don't touch it |
109 |
if (strcmp(intval($str), $str) == 0) return $str; |
if (strcmp(intval($str), $str) == 0) return $str; |
110 |
# Replace "<BR>" with "\n" |
# Replace "<BR>" with "\n" |
115 |
$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); |
116 |
# Remove "<HEAD>"/"</HEAD>", and anything in between. |
# Remove "<HEAD>"/"</HEAD>", and anything in between. |
117 |
$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); |
118 |
# Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<P>" and "BR" tags, along with their pairs |
# Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>", |
119 |
|
# "<P>" and "<BR>" tags, along with their pairs |
120 |
$str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); |
$str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); |
121 |
|
# Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>") |
122 |
|
#$str = preg_replace("/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im", '', $str); |
123 |
|
# "<P>" and "<BR>" tags, along with their pairs |
124 |
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
125 |
$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); |
126 |
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
127 |
$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); |
128 |
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
129 |
$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); |
130 |
# Replace "``" and "''" with """ (a single double quote) |
# Replace "``" and "''" with """ (normal ASCII double quote) |
131 |
$str = str_replace("“", '"', $str); |
$str = str_replace("“", '"', $str); |
132 |
$str = str_replace("”", '"', $str); |
$str = str_replace("”", '"', $str); |
133 |
# Replace "-" with "-" |
# Replace "-" with "-" |