/[health_html]/inc/global.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /inc/global.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations)
Wed Sep 19 14:16:34 2001 UTC (22 years, 8 months ago) by ravilov
Branch: MAIN
Changes since 1.11: +14 -28 lines
Fixed some bugs in my_replace() (formely nonl()) in global.php

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 ravilov 1.9 function Letters() { return "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; }
11    
12 ravilov 1.8 function Slova($alpha_only = false) {
13 ravilov 1.9 $sl = preg_split('//', Letters());
14     array_pop($sl); // The final element is empty.
15 ravilov 1.8 if (!$alpha_only) array_unshift($sl, "@");
16     return $sl;
17     }
18    
19     function MyCompare($a, $b) {
20 ravilov 1.9 $slova = Letters();
21 ravilov 1.8 $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),
23     strtr(MyUpper($b), $slova, $weights));
24     }
25    
26 ravilov 1.12 function my_replace($str, $start, $end, $pat = "", $rep = "") {
27     if (!$pat) $pat = '\s*(\r\n?|\n\r?)';
28 ravilov 1.11 $idx1 = $idx2 = -1;
29     while (true) {
30 ravilov 1.12 $str2 = strtoupper($str);
31     $idx1 = strpos($str2, $start, $idx1 + 1);
32 ravilov 1.11 if ($idx1 === false) break;
33 ravilov 1.12 $idx2 = strpos($str2, $end, $idx2 + 1);
34 ravilov 1.11 if ($idx2 === false) break;
35     if ($idx1 > $idx2) break;
36     $idx2 += strlen($end);
37 ravilov 1.12 $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 ravilov 1.11 }
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 ravilov 1.9 $str = preg_replace("/(^\\s+|\\s+$)/", "", $str);
49 ravilov 1.11 $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 ravilov 1.12 $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 ravilov 1.11 $str = str_replace('"', "&quot;", $str);
58     if (!$full) $str = str_replace("'|'", '"', $str);
59 ravilov 1.1 return $str;
60     }
61 ravilov 1.7
62     function ParseNewline($str, $paragraphs = false) {
63 ravilov 1.1 if (!$str) return $str;
64 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);
65 ravilov 1.11 return nl2br($str);
66 ravilov 1.1 }
67 ravilov 1.7
68 ravilov 1.1 function error($msg) {
69     if (is_array($msg)) $msg = implode(" ", $msg);
70 ravilov 1.7 echo "<BR>\n<FONT COLOR=\"#FF0000\">[".HTMLSpecialChars($msg)."]</FONT><BR>\n";
71 ravilov 1.1 }
72 ravilov 1.7
73     function convert_html($str) {
74     $entities = array(
75     "nbsp" => " ", "#160" => " ", # nbsp
76     "amp" => " ", "#38" => " ", # amp
77     "quot" => "\"", "#34" => "\"", # quot
78     "lt" => "<", "#60" => "<", # lt
79     "gt" => ">", "#62" => ">", # gt
80     "Scaron" => "©", "#352" => "©",
81     "scaron" => "¹", "#353" => "¹",
82 ravilov 1.8 "Ccaron" => "È", "#268" => "È", "#268" => "È",
83 ravilov 1.7 "ccaron" => "è", "#232" => "è", "#269" => "è",
84 ravilov 1.8 "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
85 ravilov 1.7 "cgrave" => "æ", "#230" => "æ", "#263" => "æ",
86 ravilov 1.8 "???" => "Ð", "#272" => "Ð", "#" => "Ð",
87     "???" => "ð", "#273" => "ð",
88     "Zcaron" => "®", "#381" => "®",
89     "zcaron" => "¾", "#382" => "¾",
90 ravilov 1.7 );
91     $t = intval($str);
92     # Skip if not a scalar
93 ravilov 1.11 if (!is_string($str)) return $str;
94 ravilov 1.7 # If a number, don't touch it
95     if (strcmp(intval($str), $str) == 0) return $str;
96     # Replace "<BR>" with "\n"
97     $str = preg_replace("/\<BR\>/m", "\n", $str);
98     # Replace "<...>\n" with "<...>"
99     $str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str);
100     # Replace "\n</...>" with "</...>\n"
101     $str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str);
102     # Remove "<HEAD>"/"</HEAD>", and anything in between.
103     $str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str);
104 ravilov 1.11 # Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>",
105     # "<P>" and "<BR>" tags, along with their pairs
106 ravilov 1.8 $str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str);
107 ravilov 1.11 # 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 ravilov 1.7 # 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);
112     # 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);
114     # 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);
116 ravilov 1.11 # Replace "``" and "''" with """ (normal ASCII double quote)
117 ravilov 1.7 $str = str_replace("“", '"', $str);
118     $str = str_replace("”", '"', $str);
119     # Replace "-" with "-"
120     $str = str_replace("—", '-', $str);
121     # Replace character references ("&...;" and "&#...;") with its value
122     $str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str);
123     # Remove all whitespace at beginning or ending of a line
124     $str = preg_replace("/(^\s+|\s+$)/", '', $str);
125     # Convert Win1250 to ISO8859-2
126     $str = strtr($str, "ŠÐÈƎšðèæž", "©ÐÈÆ®¹ðèæ¾");
127     return $str;
128 ravilov 1.1 }
129     ?>

  ViewVC Help
Powered by ViewVC 1.1.26