1 |
ravilov |
1.1 |
<?php |
2 |
ravilov |
1.8 |
function MyUpper($str) { |
3 |
|
|
return strtr(strtoupper($str), "¹ðèæ¾", "©ÐÈÆ®"); |
4 |
|
|
} |
5 |
|
|
|
6 |
|
|
function MyLower($str) { |
7 |
|
|
return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾"); |
8 |
|
|
} |
9 |
|
|
|
10 |
|
|
function Slova($alpha_only = false) { |
11 |
|
|
$sl = array("A", "B", "C", "È", "Æ", "D", "Ð", "E", "F", |
12 |
|
|
"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", |
13 |
|
|
"R", "S", "©", "T", "U", "V", "W", "X", "Y", "Z", "®"); |
14 |
|
|
if (!$alpha_only) array_unshift($sl, "@"); |
15 |
|
|
return $sl; |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
function MyCompare($a, $b) { |
19 |
|
|
$slova = "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; |
20 |
|
|
$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"; |
21 |
|
|
return strcasecmp(strtr(MyUpper($a), $slova, $weights), |
22 |
|
|
strtr(MyUpper($b), $slova, $weights)); |
23 |
|
|
} |
24 |
|
|
|
25 |
ravilov |
1.1 |
function MyEscape($str) { |
26 |
|
|
$allowed = array("", "B", "I", "U", "UL", "OL", "LI"); |
27 |
|
|
$str = preg_replace("/(\<\/?\s*(\w+)>[^\>]*\>)/e", |
28 |
ravilov |
1.8 |
"array_search(MyUpper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')", |
29 |
ravilov |
1.1 |
$str); |
30 |
ravilov |
1.2 |
$str = preg_replace("/(^\s+|\s+$)/", "", $str); |
31 |
ravilov |
1.4 |
$str = ereg_replace("\"", """, $str); |
32 |
ravilov |
1.1 |
return $str; |
33 |
|
|
} |
34 |
ravilov |
1.7 |
|
35 |
|
|
function ParseNewline($str, $paragraphs = false) { |
36 |
ravilov |
1.1 |
if (!$str) return $str; |
37 |
ravilov |
1.7 |
if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', ' </p><p class="ptext">', $str); |
38 |
|
|
$str = ereg_replace("[ \t]*(\r\n?|\n\r?)", '<br>', $str); |
39 |
ravilov |
1.1 |
return $str; |
40 |
|
|
} |
41 |
ravilov |
1.7 |
|
42 |
ravilov |
1.1 |
function error($msg) { |
43 |
|
|
if (is_array($msg)) $msg = implode(" ", $msg); |
44 |
ravilov |
1.7 |
echo "<BR>\n<FONT COLOR=\"#FF0000\">[".HTMLSpecialChars($msg)."]</FONT><BR>\n"; |
45 |
ravilov |
1.1 |
} |
46 |
ravilov |
1.7 |
|
47 |
|
|
function convert_html($str) { |
48 |
|
|
$entities = array( |
49 |
|
|
"nbsp" => " ", "#160" => " ", # nbsp |
50 |
|
|
"amp" => " ", "#38" => " ", # amp |
51 |
|
|
"quot" => "\"", "#34" => "\"", # quot |
52 |
|
|
"lt" => "<", "#60" => "<", # lt |
53 |
|
|
"gt" => ">", "#62" => ">", # gt |
54 |
|
|
"Scaron" => "©", "#352" => "©", |
55 |
|
|
"scaron" => "¹", "#353" => "¹", |
56 |
ravilov |
1.8 |
"Ccaron" => "È", "#268" => "È", "#268" => "È", |
57 |
ravilov |
1.7 |
"ccaron" => "è", "#232" => "è", "#269" => "è", |
58 |
ravilov |
1.8 |
"Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ", |
59 |
ravilov |
1.7 |
"cgrave" => "æ", "#230" => "æ", "#263" => "æ", |
60 |
ravilov |
1.8 |
"???" => "Ð", "#272" => "Ð", "#" => "Ð", |
61 |
|
|
"???" => "ð", "#273" => "ð", |
62 |
|
|
"Zcaron" => "®", "#381" => "®", |
63 |
|
|
"zcaron" => "¾", "#382" => "¾", |
64 |
ravilov |
1.7 |
); |
65 |
|
|
$t = intval($str); |
66 |
|
|
# Skip if not a scalar |
67 |
|
|
if (!is_scalar($str)) return $str; |
68 |
|
|
# If a number, don't touch it |
69 |
|
|
if (strcmp(intval($str), $str) == 0) return $str; |
70 |
|
|
# Replace "<BR>" with "\n" |
71 |
|
|
$str = preg_replace("/\<BR\>/m", "\n", $str); |
72 |
|
|
# Replace "<...>\n" with "<...>" |
73 |
|
|
$str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str); |
74 |
|
|
# Replace "\n</...>" with "</...>\n" |
75 |
|
|
$str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str); |
76 |
|
|
# Remove "<HEAD>"/"</HEAD>", and anything in between. |
77 |
|
|
$str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str); |
78 |
ravilov |
1.8 |
# Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<P>" and "BR" tags, along with their pairs |
79 |
|
|
$str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); |
80 |
ravilov |
1.7 |
# Replace "\n<LI>" or "<LI>\n" with "<LI>" |
81 |
|
|
$str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str); |
82 |
|
|
# Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively |
83 |
|
|
$str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str); |
84 |
|
|
# Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively |
85 |
|
|
$str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str); |
86 |
|
|
# Replace "``" and "''" with """ (a single double quote) |
87 |
|
|
$str = str_replace("", '"', $str); |
88 |
|
|
$str = str_replace("", '"', $str); |
89 |
|
|
# Replace "-" with "-" |
90 |
|
|
$str = str_replace("", '-', $str); |
91 |
|
|
# Replace character references ("&...;" and "&#...;") with its value |
92 |
|
|
$str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str); |
93 |
|
|
# Remove all whitespace at beginning or ending of a line |
94 |
|
|
$str = preg_replace("/(^\s+|\s+$)/", '', $str); |
95 |
|
|
# Convert Win1250 to ISO8859-2 |
96 |
|
|
$str = strtr($str, "ÐÈÆðèæ", "©ÐÈÆ®¹ðèæ¾"); |
97 |
|
|
return $str; |
98 |
ravilov |
1.1 |
} |
99 |
|
|
?> |