/[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.7 - (hide annotations)
Thu Aug 30 16:35:36 2001 UTC (22 years, 8 months ago) by ravilov
Branch: MAIN
Changes since 1.6: +63 -26 lines
Started major site rearrangement. Minor bugfixes.

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

  ViewVC Help
Powered by ViewVC 1.1.26