Вы находитесь на странице: 1из 15

<?

/ *
If you will be placing the script is not at the root of the host, and then write
in a subfolder in its value the name of the folder
and be sure to leave the front slash (/).
Example:
$ GLOBALS ['p'] = "/ board";
* /
$ GLOBALS ['p'] = "";
/ / Data to connect to the database
$ Host = "localhost"; / / Host Name
$ Bdname = "acropsra_case"; / / DB name
$ Bdlogin = "acropsra_casuser"; / / Login to the database
$ Bdpassword = "RQ1JgtRf4b5KS"; / / password for the database
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# # # # # # # # # # # # # # # # # # # Then do not touch # # # # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
setlocale (LC_ALL, 'ru_RU.UTF8', 'ru_RU', 'russian');
define ("REF", true);
/ / Session_start ();
$ H = "http://". $ _SERVER ['HTTP_HOST']. $ GLOBALS ['p']. "/";
$ U = $ h. "Upload /";
$ Im = $ h. "Images /";
$ Cdir = "cache /";
$ C_exp_dir = "cache / exp /";
$ Stylecss = "<link type=\"text/css\" href=\"".$im."style.css\" rel=\"stylesheet
\" />";
$ Mainjs = "<script type=\"text/javascript\" src=\"".$im."main.js\"> </ script>"
;
$ GLOBALS ['cq'] = 0; function cq () {$ GLOBALS ['cq'] + +;}
function gentime () {static $ a; if ($ a == 0) $ a = microtime (true); else retu
rn (string) (microtime (true) - $ a);} gentime ();
$ Db = @ mysql_connect ($ host, $ bdlogin, $ bdpassword);
if (! $ db) die (mysql_error ());
if (! @ mysql_select_db ($ bdname, $ db)) die (mysql_error ());
mysql_query ("SET NAMES utf8"); cq ();
$ Conf = mysql_query ("SELECT * FROM jb_config"); cq ();
$ C = @ mysql_fetch_assoc ($ conf);
$ Limit_pages_in_cache = 3;
$ JBSCACHE = @ $ c ['scache'];
$ JBSCACHE_expire = @ $ c ['scache_expire'];
$ JBSCACHE_exp_expire = @ $ c ['scache_exp_expire'];
$ JBKCACHE = @ $ c ['kcache'];
if (@ $ _COOKIE ['jbnocache'] == '1 ') $ JBKCACHE = "";
if (@! $ _SESSION ['email'] && @! $ _SESSION ['id_user']) {
if (@ $ _COOKIE ['email'] && @ $ _COOKIE ['id_user']) {
$ _SESSION ['Email'] = $ _COOKIE ['email'];
$ _SESSION ['Id_user'] = $ _COOKIE ['id_user'];
}}
if (@ $ _SESSION ['email'] && @ $ _SESSION ['id_user']) {
$ Userquery = mysql_query ("SELECT * FROM jb_user WHERE email = '". Addslashes (
$ _SESSION [' email ']). "'"); Cq ();
if (@ mysql_num_rows ($ userquery)) {
$ User_data = mysql_fetch_assoc ($ userquery);
if ($ _SESSION ['id_user']! = $ user_data ['pass']) {
unset ($ _SESSION ['email'], $ _SESSION ['id_user']);
session_unregister (@ $ _SESSION ['email']);
session_unregister (@ $ _SESSION ['id_user']);
session_destroy ();
} Else {
define ("USER", true);
}}}
if (ctype_alpha (@ $ _COOKIE ['jblang'])) {
if ($ _COOKIE ['jblang'] == "ru") require_once ("ru.lang.php");
elseif ($ _COOKIE ['jblang'] == "en") require_once ("en.lang.php");
else die ();
} Else {
/ / Setcookie ('jblang', 'ru', time () +77760000, "/");
/ / Require_once ("ru.lang.php");
}
if (ctype_digit (@ $ _COOKIE ['jbcity']) && @ $ _COOKIE ['jbcity']> 0) {
define ("JBCITY", $ _COOKIE ['jbcity']);
$ Qcityfromdef = mysql_query ("SELECT city_name, en_city_name FROM jb_city WHERE
id = '". JBCITY. "' LIMIT 1"); cq ();
$ Arrcityfromdef = @ mysql_fetch_assoc ($ qcityfromdef);
if (@ constant ('JBLANG') === "en") {
define ("USER_CITY_TITLE", $ arrcityfromdef ['en_city_name']);
define ("USER_CITY_TITLE_TWO", $ arrcityfromdef ['city_name']);
} Else {
define ("USER_CITY_TITLE", $ arrcityfromdef ['city_name']);
define ("USER_CITY_TITLE_TWO", $ arrcityfromdef ['en_city_name']);
}}
if ((ctype_digit (@ $ _COOKIE ['jbusernote']) && @ $ _COOKIE ['jbusernote']> 0)
| | defined ('USER')) {
if (ctype_digit (@ $ _COOKIE ['jbusernote']) && @ $ _COOKIE ['jbusernote']> 0 &&
! defined ('USER')) $ query_numr_note = "SELECT id_board FROM jb_notes WHERE id_
notes_user = '". $ _COOKIE [ 'jbusernote']. "'";
elseif (! @ $ _COOKIE ['jbusernote'] && defined ('USER')) $ query_numr_note = "S
ELECT id_board FROM jb_notes WHERE user_id = '". $ user_data [' id_user ']. "'";
elseif (ctype_digit (@ $ _COOKIE ['jbusernote']) && @ $ _COOKIE ['jbusernote']>
0 && defined ('USER')) $ query_numr_note = "SELECT id_board FROM jb_notes WHERE
user_id = '". $ user_data [' id_user ']. "' OR user_id = '". $ user_data [' id_u
ser ']. "'";
$ Qucn = mysql_query ($ query_numr_note); cq ();
$ Un_mnr = @ mysql_num_rows (@ $ qucn);
if (@ $ un_mnr) define ("COUNT_USER_NOTES", $ un_mnr);
}
function pr () {
echo "<pre> _REQUEST:"; print_r ($ _REQUEST); echo "</ pre>";
echo "<pre> _FILES:"; print_r ($ _FILES); echo "</ pre>";
echo "<pre> _SESSION:"; print_r ($ _SESSION); echo "</ pre>";
}
function smsclass ($ vip, $ sel) {
if ($ vip == 1) $ class = "topmess";
else {if ($ sel == 1) $ class = "selectmess";
else $ class = "stradv";}
return $ class;
}
function sendmailer ($ to, $ from, $ subject, $ msg) {
$ S = "=? Utf-8? B?". Base64_encode ($ subject). "? =";
$ Headers = "MIME-Version: 1.0". "\ R \ n". "Content-type: text / plain; charset
= utf-8". "\ R \ n". "From:". $ From. " \ r \ n "." Reply-To: ". $ from." \ r \
n "." Return-Path: ". $ from." \ r \ n "." X-Mailer: PHP / ". phpversion (). "\
r \ n". "Content-type: text / plain; charset = utf-8";
if ($ sendPass = mail ($ to, $ s, $ msg, $ headers)) return true; else return fa
lse;
}
function PluralForm ($ n, $ form1, $ form2, $ form5) {
$ N = abs ($ n)% 100; $ n1 = $ n% 10; if ($ n> 10 && $ n <20) return $ form5;
if ($ n1> 1 && $ n1 <5) return $ form2; if ($ n1 == 1) return $ form1; return $
form5;
}
function cleansql ($ input) {
$ Input = trim ($ input);
if (get_magic_quotes_gpc ()) $ input = stripslashes ($ input);
if (! is_numeric ($ input)) $ input = mysql_real_escape_string ($ input);
return $ input;
}
function clean ($ input) {
$ Input = strip_tags_smart ($ input);
$ Input = htmlspecialchars ($ input);
$ Input = cleansql ($ input);
return $ input;
}
function translit ($ content) {
$ Content = trim (strip_tags_smart ($ content));
$ Content = strtr ($ content, $ transA);
$ Content = strtr ($ content, $ transB);
$ Content = preg_replace ("/ \ s + / ums", "_", $ content);
$ Content = preg_replace ('/ [\ -] + / ui', '-', $ content);
$ Content = preg_replace ('/ [\.] + / U', '_', $ content);
$ Content = preg_replace ("/ [^ a-z0-9 \ _ \ - \.] + / Umi", "", $ content);
$ Content = str_replace ("/ [_] + / u", "_", $ content);
return $ content;
}
function ru2en ($ content) {
$ Content = trim (strip_tags_smart ($ content));
$ Content = strtr ($ content, $ transA);
$ Content = strtr ($ content, $ transB);
return $ content;
}
function writeData ($ path, $ data) {
$ Fp = fopen ($ path, 'w'); if (! $ Fp) {return false;}
$ Retries = 0; $ max_retries = 10;
do {if ($ retries> 0) {usleep (rand (1,10000));} $ retries + = 1;}
while (! flock ($ fp, LOCK_EX) and $ retries <= $ max_retries);
if ($ retries> = $ max_retries) {return false;}
fwrite ($ fp, "$ data \ n"); flock ($ fp, LOCK_UN); fclose ($ fp); return true;
}
function readData ($ path, $ expiry) {
if (file_exists ($ path)) {
if ((time () - $ expiry)> filemtime ($ path)) return false;
$ Cache = file ($ path); return implode ('', $ cache);
} Return false;
}
function split_punct ($ string) {
$ String = preg_replace ("/ (\. | \, | \) | \: | \; | \! | \?) / Ui", "\ \ 1", $
string);
$ Arr = explode ("", $ string);
for ($ i = 0; $ i <count ($ arr); $ i + +) {
$ Arr [$ i] = trim ($ arr [$ i]);
if (utf8_strlen ($ arr [$ i])> 30) $ arr [$ i] = chunk_split ($ arr [$ i], 30, "
");
}
$ String = implode ('', $ arr);
return $ string;
}
/ **
* @ License http://creativecommons.org/licenses/by-sa/3.0/
* @ Author Nasibullin Rinat <nasibullin at starlink ru>
* @ Charset ANSI
* @ Version 1.0.0
* /
function utf8_chunk_split ($ string, $ length = null, $ glue = null) {
if (! is_string ($ string)) trigger_error ('A string type expected in first paramete
r,'. gettype ($ string). 'given!', E_USER_ERROR);
$ Length = intval ($ length);
$ Glue = strval ($ glue);
if ($ length <1) $ length = 76;
if ($ glue ==='') $ glue = "\ r \ n";
if (! is_array ($ a = utf8_str_split ($ string, $ length))) return false;
return implode ($ glue, $ a);
}
/ **
* @ License http://creativecommons.org/licenses/by-sa/3.0/
* @ Author Nasibullin Rinat, http://orangetie.ru/
* @ Charset ANSI
* @ Version 1.2.5
* /
function utf8_convert_case ($ s, $ mode) {
static $ trans = array (
# En (English Latin)
# CASE_UPPER => case_lower
"\ X41" => "\ x61", # A a
"\ X42" => "\ x62", # B b
"\ X43" => "\ x63", # C c
"\ X44" => "\ x64", # D d
"\ X45" => "\ x65", # E e
"\ X46" => "\ x66", # F f
"\ X47" => "\ x67", # G g
"\ X48" => "\ x68", # H h
"\ X49" => "\ x69", # I i
"\ X4a" => "\ x6a", # J j
"\ X4b" => "\ x6b", # K k
"\ X4c" => "\ x6c", # L l
"\ X4d" => "\ x6d", # M m
"\ X4e" => "\ x6e", # N n
"\ X4f" => "\ x6f", # O o
"\ X50" => "\ x70", # P p
"\ X51" => "\ x71", # Q q
"\ X52" => "\ x72", # R r
"\ X53" => "\ x73", # S s
"\ X54" => "\ x74", # T t
"\ X55" => "\ x75", # U u
"\ X56" => "\ x76", # V v
"\ X57" => "\ x77", # W w
"\ X58" => "\ x78", # X x
"\ X59" => "\ x79", # Y y
"\ X5a" => "\ x7a", # Z z
# Ru (Russian Cyrillic)
# CASE_UPPER => case_lower
"\ Xd0 \ x81" => "\ xd1 \ x91", # E e
"\ Xd0 \ x90" => "\ xd0 \ xb0", # A and
"\ Xd0 \ x91" => "\ xd0 \ xb1", # B b
"\ Xd0 \ x92" => "\ xd0 \ xb2", # B
"\ Xd0 \ x93" => "\ xd0 \ xb3", # D g
"\ Xd0 \ x94" => "\ xd0 \ xb4", # D d
"\ Xd0 \ x95" => "\ xd0 \ xb5", # E e
"\ Xd0 \ x96" => "\ xd0 \ xb6", # F F
"\ Xd0 \ x97" => "\ xd0 \ xb7", # W h
"\ Xd0 \ x98" => "\ xd0 \ xb8", # I and
"\ Xd0 \ x99" => "\ xd0 \ xb9", # J st
"\ Xd0 \ x9a" => "\ xd0 \ xba", # K to
"\ Xd0 \ x9b" => "\ xd0 \ xbb", # L L
"\ Xd0 \ x9c" => "\ xd0 \ xbc", # M m
"\ Xd0 \ x9d" => "\ xd0 \ xbd", # H n
"\ Xd0 \ x9e" => "\ xd0 \ xbe", # Oh oh
"\ Xd0 \ x9f" => "\ xd0 \ xbf", # P n
# CASE_UPPER => case_lower
"\ Xd0 \ xa0" => "\ xd1 \ x80", # P p
"\ Xd0 \ xa1" => "\ xd1 \ x81", # C
"\ Xd0 \ xa2" => "\ xd1 \ x82", # T t
"\ Xd0 \ xa3" => "\ xd1 \ x83", # We have
"\ Xd0 \ xa4" => "\ xd1 \ x84", # FF
"\ Xd0 \ xa5" => "\ xd1 \ x85", # X x
"\ Xd0 \ xa6" => "\ xd1 \ x86", # C n
"\ Xd0 \ xa7" => "\ xd1 \ x87", # W h
"\ Xd0 \ xa8" => "\ xd1 \ x88", # W w
"\ Xd0 \ xa9" => "\ xd1 \ x89", # ni ni
"\ Xd0 \ xaa" => "\ xd1 \ x8a", # b b
"\ Xd0 \ xab" => "\ xd1 \ x8b", # s s
"\ Xd0 \ xac" => "\ xd1 \ x8c", # b s
"\ Xd0 \ xad" => "\ xd1 \ x8d", # E e
"\ Xd0 \ xae" => "\ xd1 \ x8e", # Yu Yu
"\ Xd0 \ xaf" => "\ xd1 \ x8f", # I I
# Tt (Tatar, Bashkir Cyrillic)
# CASE_UPPER => case_lower
"\ Xd2 \ x96" => "\ xd2 \ x97", # F Well-plus =>
"\ Xd2 \ xa2" => "\ xd2 \ xa3", # H n-something =>
"\ Xd2 \ xae" => "\ xd2 \ xaf", # Y y Y => Y
"\ Xd2 \ xba" => "\ xd2 \ xbb", # h h soft =>
"\ Xd3 \ x98" => "\ xd3 \ x99", # E e =>
"\ Xd3 \ xa8" => "\ xd3 \ xa9", # O o crossed =>
# Uk (Ukrainian Cyrillic)
# CASE_UPPER => case_lower
"\ Xd2 \ x90" => "\ xd2 \ x91", # g-plus
"\ Xd0 \ x84" => "\ xd1 \ x94", # e flip
"\ Xd0 \ x86" => "\ xd1 \ x96", # and a single point
"\ Xd0 \ x87" => "\ xd1 \ x97", #, and with two points
# Be (Belarusian Cyrillic)
# CASE_UPPER => case_lower
"\ Xd0 \ x8e" => "\ xd1 \ x9e", # with a horseshoe over a letter
# Tr, de, es (Turkish, German, Spanish, French, Latin)
# CASE_UPPER => case_lower
"\ Xc3 \ x84" => "\ xc3 \ xa4", # a umlaut => (Turkish)
"\ Xc3 \ x87" => "\ xc3 \ xa7", # c-plus => (Turkish, French)
"\ Xc3 \ x91" => "\ xc3 \ xb1", # n with tilde => (Turkish, Spanish)
"\ Xc3 \ x96" => "\ xc3 \ xb6", # o umlaut => (Turkish)
"\ Xc3 \ x9c" => "\ xc3 \ xbc", # u umlaut => (Turkish, French)
"\ Xc4 \ x9e" => "\ xc4 \ x9f", # g umlaut => (Turkish)
"\ Xc4 \ xb0" => "\ xc4 \ xb1", # ic point, not => (Turkish)
"\ Xc5 \ x9e" => "\ xc5 \ x9f", # s-something => (Turkish)
# Hr (Croatian Latin)
# CASE_UPPER => case_lower
"\ Xc4 \ x8c" => "\ xc4 \ x8d", # c with a horseshoe over a letter
"\ Xc4 \ x86" => "\ xc4 \ x87", # c with an accent
"\ Xc4 \ x90" => "\ xc4 \ x91", # d crossed
"\ Xc5 \ xa0" => "\ xc5 \ xa1", # s with a horseshoe over a letter
"\ Xc5 \ xbd" => "\ xc5 \ xbe", # z with a horseshoe over a letter
# Fr (French Latin)
# CASE_UPPER => case_lower
"\ Xc3 \ x80" => "\ xc3 \ xa0", # a accented in other direction
"\ Xc3 \ x82" => "\ xc3 \ xa2", # a with a lid
"\ Xc3 \ x86" => "\ xc3 \ xa6", # ae combined
"\ Xc3 \ x88" => "\ xc3 \ xa8", # e with an accent in the other direction
"\ Xc3 \ x89" => "\ xc3 \ xa9", # e with an accent
"\ Xc3 \ x8a" => "\ xc3 \ xaa", # e with lid
"\ Xc3 \ x8b" => "\ xc3 \ xab", # f
"\ Xc3 \ x8e" => "\ xc3 \ xae", # i with cover
"\ Xc3 \ x8f" => "\ xc3 \ xaf", # i umlaut
"\ Xc3 \ x94" => "\ xc3 \ xb4", # o with lid
"\ Xc5 \ x92" => "\ xc5 \ x93", # ce combined
"\ Xc3 \ x99" => "\ xc3 \ xb9", # u accented in other direction
"\ Xc3 \ x9b" => "\ xc3 \ xbb", # u with lid
"\ Xc5 \ xb8" => "\ xc3 \ xbf", # y umlaut
# Xx (other language)
# CASE_UPPER => case_lower
# "" => "", #
);
if ($ mode == CASE_UPPER) {
if (function_exists ('mb_strtoupper')) return mb_strtoupper ($ s, 'utf-8');
if (preg_match ('/ ^ [\ x00-\ x7e] * $ /', $ s)) return strtoupper ($ s);
return strtr ($ s, array_flip ($ trans));
}
elseif ($ mode == CASE_LOWER)
{
if (function_exists ('mb_strtolower')) return mb_strtolower ($ s, 'utf-8');
if (preg_match ('/ ^ [\ x00-\ x7e] * $ /', $ s)) return strtolower ($ s);
return strtr ($ s, $ trans);
} Else {
trigger_error ('Parameter 2 should be a constant of CASE_LOWER or CASE_UPPER!',
E_USER_WARNING);
return $ s;
}
return $ s;
}
function utf8_strtolower ($ s) {
return utf8_convert_case ($ s, CASE_LOWER);
}
function utf8_uppercase ($ s) {
return utf8_convert_case ($ s, CASE_UPPER);
}
function utf8_lowercase ($ s) {
return utf8_convert_case ($ s, CASE_LOWER);
}
function utf8_ucfirst ($ s, $ is_other_to_lowercase = true) {
if ($ s ==='' or! is_string ($ s)) return $ s;
if (preg_match ('/ ^ (.) (. *) $ / us', $ s, $ m) === false) return false;
return utf8_uppercase ($ m [1]). ($ is_other_to_lowercase? utf8_lowercase ($ m [2]):
$ m [2]);
}
function img_resize ($ src, $ dest, $ width, $ tolarge, $ bgcolor, $ ext, $ imgw
idth, $ imgheight, $ logomerge) {
if (! file_exists ($ src)) return false;
$ Icfunc = "imagecreatefrom". $ Ext;
if (! function_exists ($ icfunc)) return false;
if ($ tolarge! = '1 '&& $ imgheight <$ width) $ width = $ imgheight;
$ X_ratio = $ width / $ imgheight;
$ Y_ratio = $ width / $ imgwidth;
$ Ratio = min ($ x_ratio, $ y_ratio);
$ Use_x_ratio = ($ x_ratio == $ ratio);
$ New_width = $ use_x_ratio? $ Width: floor ($ imgheight * $ ratio);
$ New_height =! $ Use_x_ratio? $ Width: floor ($ imgwidth * $ ratio);
$ Isrc = $ icfunc ($ src);
if ($ bgcolor! = 0) {
$ New_left = $ use_x_ratio? 0: floor (($ width-$ new_width) / 2);
$ New_top =! $ Use_x_ratio? 0: floor (($ width-$ new_height) / 2);
$ Nn_width = $ nn_height = $ width;
$ Bgc = $ bgcolor;
} Else {
$ New_left = 0;
$ New_top = 0;
$ Nn_width = $ new_width;
$ Nn_height = $ new_height;
$ Bgc = 0xFFFFFF;
}
$ Idest = imagecreatetruecolor ($ nn_width, $ nn_height);
imagefill ($ idest, 0,0, $ bgc);
imagecopyresampled ($ idest, $ isrc, $ new_left, $ new_top, 0,0, $ new_width, $
new_height, $ imgheight, $ imgwidth);
if ($ logomerge == "1") {
$ Mergelogo = $ _SERVER ['DOCUMENT_ROOT']. $ GLOBALS ['p']. "/ Images / logo_mer
ge / logoj.gif";
if (file_exists ($ mergelogo)) {
$ Size_logo = getimagesize ($ mergelogo);
if ($ size_logo [2] == 1) $ logo = imagecreatefromgif ($ mergelogo);
elseif ($ size_logo [2] == 2) $ logo = imagecreatefromjpeg ($ mergelogo);
elseif ($ size_logo [2] == 3) $ logo = imagecreatefrompng ($ mergelogo);
if (@ $ logo) {
if ($ nn_width> ($ size_logo [0] +50) && $ nn_height> ($ size_logo [1] 50)) {
$ Coordmerge_x = $ nn_width-($ size_logo [0] 20);
$ Coordmerge_y = $ nn_height-($ size_logo [1] 20);
imagecopymerge ($ idest, $ logo, $ coordmerge_x, $ coordmerge_y, 0,0, $ size_logo
[0], $ size_logo [1], 100);
}} Else {return false;}
} Else {return false;}
}
if ($ ext == "gif") imagegif ($ idest, $ dest);
elseif ($ ext == "png") imagepng ($ idest, $ dest);
else imagejpeg ($ idest, $ dest, 100);
imagedestroy ($ isrc);
imagedestroy ($ idest);
return true;
}
/ **
* @ Author Nasibullin Rinat, http://orangetie.ru/
* /
function utf8_str_split ($ string, $ length = null) {
if (! is_string ($ string)) trigger_error ('A string type expected in first para
meter,'. gettype ($ string). 'given!', E_USER_ERROR);
$ Length = ($ length === null)? 1: intval ($ length);
if ($ length <1) return false;
if ($ length <100) {
preg_match_all ('/ (?> [\ x09 \ x0A \ x0D \ x20-\ x7E] # ASCII
| [\ XC2-\ xDF] [\ x80-\ xBF] # non-overlong 2-byte
| \ XE0 [\ xA0-\ xBF] [\ x80-\ xBF] # excluding overlongs
| [\ XE1-\ xEC \ xEE \ xEF] [\ x80-\ xBF] {2} # straight 3-byte
| \ XED [\ x80-\ x9F] [\ x80-\ xBF] # excluding surrogates
| \ XF0 [\ x90-\ xBF] [\ x80-\ xBF] {2} # planes 1-3
| [\ XF1-\ xF3] [\ x80-\ xBF] {3} # planes 4-15
| \ XF4 [\ x80-\ x8F] [\ x80-\ xBF] {2} # plane 16
# | (.) # Catch bad bytes
) {1 '. $ Length. '}
/ XsSX ', $ string, $ m);
$ A = & $ m [0];
} Else {
preg_match_all ('/ (?> [\ x09 \ x0A \ x0D \ x20-\ x7E] # ASCII
| [\ XC2-\ xDF] [\ x80-\ xBF] # non-overlong 2-byte
| \ XE0 [\ xA0-\ xBF] [\ x80-\ xBF] # excluding overlongs
| [\ XE1-\ xEC \ xEE \ xEF] [\ x80-\ xBF] {2} # straight 3-byte
| \ XED [\ x80-\ x9F] [\ x80-\ xBF] # excluding surrogates
| \ XF0 [\ x90-\ xBF] [\ x80-\ xBF] {2} # planes 1-3
| [\ XF1-\ xF3] [\ x80-\ xBF] {3} # planes 4-15
| \ XF4 [\ x80-\ x8F] [\ x80-\ xBF] {2} # plane 16
# | (.) # Catch bad bytes
)
/ XsSX ', $ string, $ m);
$ A = array ();
for ($ i = 0, $ c = count ($ m [0]); $ i <$ c; $ i + = $ length) $ a [] = implod
e ('', array_slice ($ m [0] $ i, $ length));
}
$ Distance = strlen ($ string) - strlen (implode ('', $ a));
if ($ distance> 0) {
trigger_error ('Charset is not UTF-8, total'. $ distance. 'unknown bytes found!'
, E_USER_WARNING);
return false;
}
return $ a;
}
/ **
* @ Author Nasibullin Rinat, http://orangetie.ru/
* /
function utf8_substr ($ str, $ offset, $ length = null) {
if (function_exists ('mb_substr')) return mb_substr ($ str, $ offset, $ length,
'utf-8');
if (function_exists ('iconv_substr')) return iconv_substr ($ str, $ offset, $ le
ngth, 'utf-8');
if (! is_array ($ a = utf8_str_split ($ str))) return false;
if ($ length! == null) $ a = array_slice ($ a, $ offset, $ length);
else $ a = array_slice ($ a, $ offset);
return implode ('', $ a);}
/ **
* @ Author <chernyshevsky at hotmail dot com>
* @ Author Nasibullin Rinat, http://orangetie.ru/
* /
function utf8_strlen ($ str) {
if (function_exists ('mb_strlen')) return mb_strlen ($ str, 'utf-8');
return strlen (utf8_decode ($ str));}
/ **
* @ Author Nasibullin Rinat, http://orangetie.ru/
* /
function utf8_strpos ($ haystack, $ needle, $ offset = null) {
if ($ offset === null or $ offset <0) $ offset = 0;
if (function_exists ('mb_strpos')) return mb_strpos ($ haystack, $ needle, $ off
set, 'utf-8');
if (function_exists ('iconv_strpos')) return iconv_strpos ($ haystack, $ needle,
$ offset, 'utf-8');
$ Byte_pos = $ offset;
do if (($ byte_pos = strpos ($ haystack, $ needle, $ byte_pos)) === false) retur
n false;
while (($ char_pos = utf8_strlen (substr ($ haystack, 0, $ byte_pos + +))) <$ of
fset);
return $ char_pos;
}
/ **
* @ Author Nasibullin Rinat, http://orangetie.ru/
* /
function strip_tags_smart ($ s, array $ allowable_tags = null, $ is_format_space
s = true, array $ pair_tags = array ('script', 'style', 'map', 'iframe', 'frames
et', 'object', 'applet' , 'comment', 'button', 'textarea', 'select'), array $ pa
ra_tags = array ('p', 'td', 'th', 'li', 'h1', 'h2', 'h3 ',' h4 ',' h5 ',' h6 ','
div ',' form ',' title ',' pre ')) {
static $ _callback_type = false;
static $ _allowable_tags = array ();
static $ _para_tags = array ();
static $ re_attrs_fast_safe = '(?! [a-zA-Z \ d]) # statement, which follows afte
r a tag
# Correct attributes
(?>
[^> "\ '] +
| (? <= [\ = \ X20 \ r \ n \ t] | \ xc2 \ xa0) "[^"] * "
| (? <= [\ = \ X20 \ r \ n \ t] | \ xc2 \ xa0) \ '[^ \'] * \ '
) *
# Incorrect attributes
[^>] * + ';
if (is_array ($ s)) {
if ($ _callback_type === 'strip_tags') {
$ Tag = strtolower ($ s [1]);
if ($ _allowable_tags &&
(Array_key_exists ($ tag, $ _allowable_tags) | | array_key_exists ('<'. Trim (st
rtolower ($ s [0]), '</>'). '>', $ _allowable_tags))
) Return $ s [0];
if ($ tag === 'br') return "\ r \ n";
if ($ _para_tags && array_key_exists ($ tag, $ _para_tags)) return "\ r \ n \ r
\ n";
return'';
}
trigger_error ('Unknown callback type "'. $ _callback_type. '"!', E_USER_ERROR);
}
if (($ pos = strpos ($ s, '<')) === false | | strpos ($ s, '>', $ pos) === false
) {
return $ s;
}
$ Length = strlen ($ s);
$ Re_tags = '/ <[\ / \!]? +
(
[A-zA-Z] [a-zA-Z \ d] * +
(?> \: [A-zA-Z] [a-zA-Z \ d] * +)?
)
'. $ Re_attrs_fast_safe. '
>
/ SxSX ';
$ Patterns = array (
'/ <([\? \%]). *? \ \ 1> / sxSX ',
'/ <\! \ [CDATA \ [. *? \] \]> / SxSX ',
'/ <\! -. *? -> / SSX',
'/ <\! (?: -)? +
\ [
(?> [^ \] "\ '] + |" [^ "] *" | \' [^ \ '] * \') *
\]
(?: -)? +
>
/ SxSX ',
);
if ($ pair_tags) {
foreach ($ pair_tags as $ k => $ v) $ pair_tags [$ k] = preg_quote ($ v, '/');
$ Patterns [] = '/ <((? I:'. Implode ('|', $ pair_tags). '))'. $ Re_attrs_fast_s
afe. '(<! \ /)>
. *?
<\ / (? I: \ \ 1) '. $ Re_attrs_fast_safe. '>
/ SxSX ';
}
$ I = 0;
$ Max = 99;
while ($ i <$ max) {
$ S2 = preg_replace ($ patterns,'', $ s);
if (preg_last_error ()! == PREG_NO_ERROR) {
$ I = 999;
break;
}
if ($ i == 0) {
$ Is_html = ($ s2! = $ S | | preg_match ($ re_tags, $ s2));
if (preg_last_error ()! == PREG_NO_ERROR) {
$ I = 999;
break;
}
if ($ is_html) {
if ($ is_format_spaces) {
/ *
In the PCRE library for PHP \ s - it whitespace, namely, the character class [\
x09 \ x0a \ x0c \ x0d \ x20 \ xa0] or, on the other, [\ t \ n \ f \ r \ xa0]
If \ s modifier is used with / u, that \ s is interpreted as [\ x09 \ x0a \ x0c
\ x0d \ x20]
Browser does not distinguish between the white space, one after another consecut
ive symbols are seen as one
* /
# $ S2 = str_replace (array ("\ r", "\ n", "\ t"), '', $ s2);
# $ S2 = strtr ($ s2, "\ x09 \ x0a \ x0c \ x0d", '');
$ S2 = preg_replace ('/ [\ x09 \ x0a \ x0c \ x0d] + +
| <((? I: pre | textarea)) '. $ Re_attrs_fast_safe. '(<! \ /)>
. +?
<\ / (? I: \ \ 1) '. $ Re_attrs_fast_safe. '>
\ K
/ SxSX ',' ', $ s2);
if (preg_last_error ()! == PREG_NO_ERROR) {
$ I = 999;
break;
}}
if ($ allowable_tags) $ _allowable_tags = array_flip ($ allowable_tags);
if ($ para_tags) $ _para_tags = array_flip ($ para_tags);
}}
if ($ is_html) {
$ _callback_type = 'Strip_tags';
$ S2 = preg_replace_callback ($ re_tags, __ FUNCTION__, $ s2);
$ _callback_type = False;
if (preg_last_error ()! == PREG_NO_ERROR) {
$ I = 999;
break;
}}
if ($ s === $ s2) break;
$ S = $ s2; $ i + +;
}
if ($ i> = $ max) $ s = strip_tags ($ s);
if ($ is_format_spaces && strlen ($ s)! == $ length) {
$ S = preg_replace ('/ \ x20 \ x20 + + / sSX', '', trim ($ s));
$ S = str_replace (array ("\ r \ n \ x20", "\ x20 \ r \ n"), "\ r \ n", $ s);
$ S = preg_replace ('/ [\ r \ n] {3,} + / sSX', "\ r \ n \ r \ n", $ s);
}
return $ s;
}
/ **
* @ Author Nasibullin Rinat, http://orangetie.ru/
* /
function is_utf8 (& $ data, $ is_strict = true) {
if (is_array ($ data)) {
foreach ($ data as $ k => & $ v) if (! is_utf8 ($ v, $ is_strict)) return false;
return true;
}
elseif (is_string ($ data)) {
if (function_exists ('iconv')) {
$ Distance = strlen ($ data) - strlen (@ iconv ('UTF-8', 'UTF-8 / / IGNORE', $ d
ata));
if ($ distance> 0) return false;
if ($ is_strict && preg_match ('/ [^ \ x09 \ x0A \ x0D \ x20-\ xFF] / sSX', $ da
ta)) return false;
return true;
}
$ Result = $ is_strict?
preg_replace ('/ (?> [\ x09 \ x0A \ x0D \ x20-\ x7E] # ASCII
| [\ XC2-\ xDF] [\ x80-\ xBF] # non-overlong 2-byte
| \ XE0 [\ xA0-\ xBF] [\ x80-\ xBF] # excluding overlongs
| [\ XE1-\ xEC \ xEE \ xEF] [\ x80-\ xBF] {2} # straight 3-byte
| \ XED [\ x80-\ x9F] [\ x80-\ xBF] # excluding surrogates
| \ XF0 [\ x90-\ xBF] [\ x80-\ xBF] {2} # planes 1-3
| [\ XF1-\ xF3] [\ x80-\ xBF] {3} # planes 4-15
| \ XF4 [\ x80-\ x8F] [\ x80-\ xBF] {2} # plane 16
# | (.) # Catch bad bytes
) *
/ SxSX ','', $ data):
preg_replace ('/ \ X * / suSX','', $ data);
if (function_exists ('preg_last_error')) {
if (preg_last_error () === PREG_NO_ERROR) return $ result ==='';
if (preg_last_error () === PREG_BAD_UTF8_ERROR) return false;
}
elseif (is_string ($ result)) return $ result ==='';
return utf8_check ($ data, $ is_strict);
}
elseif (is_scalar ($ data) | | is_null ($ data)) return true;
trigger_error ('Scalar, null or array type expected,'. gettype ($ data). 'given'
, E_USER_WARNING);
return false;
}
/ **
* @ Author <bmorel at ssi dot fr>
* @ Author Nasibullin Rinat, http://orangetie.ru/ (small changes)
* /
function utf8_check ($ str, $ is_strict = true) {
for ($ i = 0, $ len = strlen ($ str); $ i <$ len; $ i + +) {
$ C = ord ($ str [$ i]);
if ($ c <0x80) {
if ($ is_strict === false | | ($ c> 0x1F && $ c <0x7F) | | $ c == 0x09 | | $ c =
= 0x0A | | $ c == 0x0D) continue;
}
if (($ c & 0xE0) == 0xC0) $ n = 1;
elseif (($ c & 0xF0) == 0xE0) $ n = 2;
elseif (($ c & 0xF8) == 0xF0) $ n = 3;
elseif (($ c & 0xFC) == 0xF8) $ n = 4;
elseif (($ c & 0xFE) == 0xFC) $ n = 5;
else return false;
for ($ j = 0; $ j <$ n; $ j + +) {
$ I + +;
if ($ i == $ len | | ((ord ($ str [$ i]) & 0xC0)! = 0x80)) return false;
}}
return true;
}
/ **
* @ Author Nasibullin Rinat, http://orangetie.ru/
* /
function cp1259_to_utf8 (& $ str) {
static $ trans = array (
"\ X80" => "\ xd3 \ x98", # 0x04d8 CYRILLIC CAPITAL LETTER SCHWA
"\ X81" => "\ xd0 \ x83", # 0x0403 CYRILLIC CAPITAL LETTER GJE
"\ X82" => "\ xe2 \ x80 \ x9a", # 0x201a SINGLE LOW-9 QUOTATION MARK
"\ X83" => "\ xd1 \ x93", # 0x0453 CYRILLIC SMALL LETTER GJE
"\ X84" => "\ xe2 \ x80 \ x9e", # 0x201e DOUBLE LOW-9 QUOTATION MARK
"\ X85" => "\ xe2 \ x80 \ xa6", # 0x2026 HORIZONTAL ELLIPSIS
"\ X86" => "\ xe2 \ x80 \ xa0", # 0x2020 DAGGER
"\ X87" => "\ xe2 \ x80 \ xa1", # 0x2021 DOUBLE DAGGER
"\ X88" => "\ xe2 \ x82 \ xac", # 0x20ac EURO SIGN
"\ X89" => "\ xe2 \ x80 \ xb0", # 0x2030 PER MILLE SIGN
"\ X8a" => "\ xd3 \ xa8", # 0x04e8 CYRILLIC CAPITAL LETTER BARRED O
"\ X8b" => "\ xe2 \ x80 \ xb9", # 0x2039 SINGLE LEFT-POINTING ANGLE QUOTATION MA
RK
"\ X8c" => "\ xd2 \ xae", # 0x04ae CYRILLIC CAPITAL LETTER STRAIGHT U
"\ X8d" => "\ xd2 \ x96", # 0x0496 CYRILLIC CAPITAL LETTER ZHE WITH DESCENDER
"\ X8e" => "\ xd2 \ xa2", # 0x04a2 CYRILLIC CAPITAL LETTER EN WITH HOOK
"\ X8f" => "\ xd2 \ xba", # 0x04ba CYRILLIC CAPITAL LETTER SHHA
"\ X90" => "\ xd3 \ x99", # 0x04d9 CYRILLIC SMALL LETTER SCHWA
"\ X91" => "\ xe2 \ x80 \ x98", # 0x2018 LEFT SINGLE QUOTATION MARK
"\ X92" => "\ xe2 \ x80 \ x99", # 0x2019 RIGHT SINGLE QUOTATION MARK
"\ X93" => "\ xe2 \ x80 \ x9c", # 0x201c LEFT DOUBLE QUOTATION MARK
"\ X94" => "\ xe2 \ x80 \ x9d", # 0x201d RIGHT DOUBLE QUOTATION MARK
"\ X95" => "\ xe2 \ x80 \ xa2", # 0x2022 BULLET
"\ X96" => "\ xe2 \ x80 \ x93", # 0x2013 EN DASH
"\ X97" => "\ xe2 \ x80 \ x94", # 0x2014 EM DASH
# "\ X98" # UNDEFINED
"\ X99" => "\ xe2 \ x84 \ xa2", # 0x2122 TRADE MARK SIGN
"\ X9a" => "\ xd3 \ xa9", # 0x04e9 CYRILLIC SMALL LETTER BARRED O
"\ X9b" => "\ xe2 \ x80 \ xba", # 0x203a SINGLE RIGHT-POINTING ANGLE QUOTATION M
ARK
"\ X9c" => "\ xd2 \ xaf", # 0x04af CYRILLIC SMALL LETTER STRAIGHT U
"\ X9d" => "\ xd2 \ x97", # 0x0497 CYRILLIC SMALL LETTER ZHE WITH DESCENDER
"\ X9e" => "\ xd2 \ xa3", # 0x04a3 CYRILLIC SMALL LETTER EN WITH HOOK
"\ X9f" => "\ xd2 \ xbb", # 0x04bb CYRILLIC SMALL LETTER SHHA
"\ Xa0" => "\ xc2 \ xa0", # 0x00a0 NO-BREAK SPACE
"\ Xa1" => "\ xd0 \ x8e", # 0x040e CYRILLIC CAPITAL LETTER SHORT U
"\ Xa2" => "\ xd1 \ x9e", # 0x045e CYRILLIC SMALL LETTER SHORT U
"\ Xa3" => "\ xd0 \ x88", # 0x0408 CYRILLIC CAPITAL LETTER JE
"\ Xa4" => "\ xc2 \ xa4", # 0x00a4 CURRENCY SIGN
"\ Xa5" => "\ xd2 \ x90", # 0x0490 CYRILLIC CAPITAL LETTER GHE WITH UPTURN
"\ Xa6" => "\ xc2 \ xa6", # 0x00a6 BROKEN BAR
"\ Xa7" => "\ xc2 \ xa7", # 0x00a7 SECTION SIGN
"\ Xa8" => "\ xd0 \ x81", # 0x0401 CYRILLIC CAPITAL LETTER IO
"\ Xa9" => "\ xc2 \ xa9", # 0x00a9 COPYRIGHT SIGN
"\ Xaa" => "\ xd0 \ x84", # 0x0404 CYRILLIC CAPITAL LETTER UKRAINIAN IE
"\ Xab" => "\ xc2 \ xab", # 0x00ab LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
"\ Xac" => "\ xc2 \ xac", # 0x00ac NOT SIGN
"\ Xad" => "\ xc2 \ xad", # 0x00ad SOFT HYPHEN
"\ Xae" => "\ xc2 \ xae", # 0x00ae REGISTERED SIGN
"\ Xaf" => "\ xd0 \ x87", # 0x0407 CYRILLIC CAPITAL LETTER YI
"\ Xb0" => "\ xc2 \ xb0", # 0x00b0 DEGREE SIGN
"\ Xb1" => "\ xc2 \ xb1", # 0x00b1 PLUS-MINUS SIGN
"\ Xb2" => "\ xd0 \ x86", # 0x0406 CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIA
N I
"\ Xb3" => "\ xd1 \ x96", # 0x0456 CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN
I
"\ Xb4" => "\ xd2 \ x91", # 0x0491 CYRILLIC SMALL LETTER GHE WITH UPTURN
"\ Xb5" => "\ xc2 \ xb5", # 0x00b5 MICRO SIGN
"\ Xb6" => "\ xc2 \ xb6", # 0x00b6 PILCROW SIGN
"\ Xb7" => "\ xc2 \ xb7", # 0x00b7 MIDDLE DOT
"\ Xb8" => "\ xd1 \ x91", # 0x0451 CYRILLIC SMALL LETTER IO
"\ Xb9" => "\ xe2 \ x84 \ x96", # 0x2116 NUMERO SIGN
"\ Xba" => "\ xd1 \ x94", # 0x0454 CYRILLIC SMALL LETTER UKRAINIAN IE
"\ Xbb" => "\ xc2 \ xbb", # 0x00bb RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
"\ Xbc" => "\ xd1 \ x98", # 0x0458 CYRILLIC SMALL LETTER JE
"\ Xbd" => "\ xd0 \ x85", # 0x0405 CYRILLIC CAPITAL LETTER DZE
"\ Xbe" => "\ xd1 \ x95", # 0x0455 CYRILLIC SMALL LETTER DZE
"\ Xbf" => "\ xd1 \ x97", # 0x0457 CYRILLIC SMALL LETTER YI
"\ Xc0" => "\ xd0 \ x90", # 0x0410 CYRILLIC CAPITAL LETTER A
"\ Xc1" => "\ xd0 \ x91", # 0x0411 CYRILLIC CAPITAL LETTER BE
"\ Xc2" => "\ xd0 \ x92", # 0x0412 CYRILLIC CAPITAL LETTER VE
"\ Xc3" => "\ xd0 \ x93", # 0x0413 CYRILLIC CAPITAL LETTER GHE
"\ Xc4" => "\ xd0 \ x94", # 0x0414 CYRILLIC CAPITAL LETTER DE
"\ Xc5" => "\ xd0 \ x95", # 0x0415 CYRILLIC CAPITAL LETTER IE
"\ Xc6" => "\ xd0 \ x96", # 0x0416 CYRILLIC CAPITAL LETTER ZHE
"\ Xc7" => "\ xd0 \ x97", # 0x0417 CYRILLIC CAPITAL LETTER ZE
"\ Xc8" => "\ xd0 \ x98", # 0x0418 CYRILLIC CAPITAL LETTER I
"\ Xc9" => "\ xd0 \ x99", # 0x0419 CYRILLIC CAPITAL LETTER SHORT I
"\ Xca" => "\ xd0 \ x9a", # 0x041a CYRILLIC CAPITAL LETTER KA
"\ Xcb" => "\ xd0 \ x9b", # 0x041b CYRILLIC CAPITAL LETTER EL
"\ Xcc" => "\ xd0 \ x9c", # 0x041c CYRILLIC CAPITAL LETTER EM
"\ Xcd" => "\ xd0 \ x9d", # 0x041d CYRILLIC CAPITAL LETTER EN
"\ Xce" => "\ xd0 \ x9e", # 0x041e CYRILLIC CAPITAL LETTER O
"\ Xcf" => "\ xd0 \ x9f", # 0x041f CYRILLIC CAPITAL LETTER PE
"\ Xd0" => "\ xd0 \ xa0", # 0x0420 CYRILLIC CAPITAL LETTER ER
"\ Xd1" => "\ xd0 \ xa1", # 0x0421 CYRILLIC CAPITAL LETTER ES
"\ Xd2" => "\ xd0 \ xa2", # 0x0422 CYRILLIC CAPITAL LETTER TE
"\ Xd3" => "\ xd0 \ xa3", # 0x0423 CYRILLIC CAPITAL LETTER U
"\ Xd4" => "\ xd0 \ xa4", # 0x0424 CYRILLIC CAPITAL LETTER EF
"\ Xd5" => "\ xd0 \ xa5", # 0x0425 CYRILLIC CAPITAL LETTER HA
"\ Xd6" => "\ xd0 \ xa6", # 0x0426 CYRILLIC CAPITAL LETTER TSE
"\ Xd7" => "\ xd0 \ xa7", # 0x0427 CYRILLIC CAPITAL LETTER CHE
"\ Xd8" => "\ xd0 \ xa8", # 0x0428 CYRILLIC CAPITAL LETTER SHA
"\ Xd9" => "\ xd0 \ xa9", # 0x0429 CYRILLIC CAPITAL LETTER SHCHA
"\ Xda" => "\ xd0 \ xaa", # 0x042a CYRILLIC CAPITAL LETTER HARD SIGN
"\ Xdb" => "\ xd0 \ xab", # 0x042b CYRILLIC CAPITAL LETTER YERU
"\ Xdc" => "\ xd0 \ xac", # 0x042c CYRILLIC CAPITAL LETTER SOFT SIGN
"\ Xdd" => "\ xd0 \ xad", # 0x042d CYRILLIC CAPITAL LETTER E
"\ Xde" => "\ xd0 \ xae", # 0x042e CYRILLIC CAPITAL LETTER YU
"\ Xdf" => "\ xd0 \ xaf", # 0x042f CYRILLIC CAPITAL LETTER YA
"\ Xe0" => "\ xd0 \ xb0", # 0x0430 CYRILLIC SMALL LETTER A
"\ Xe1" => "\ xd0 \ xb1", # 0x0431 CYRILLIC SMALL LETTER BE
"\ Xe2" => "\ xd0 \ xb2", # 0x0432 CYRILLIC SMALL LETTER VE
"\ Xe3" => "\ xd0 \ xb3", # 0x0433 CYRILLIC SMALL LETTER GHE
"\ Xe4" => "\ xd0 \ xb4", # 0x0434 CYRILLIC SMALL LETTER DE
"\ Xe5" => "\ xd0 \ xb5", # 0x0435 CYRILLIC SMALL LETTER IE
"\ Xe6" => "\ xd0 \ xb6", # 0x0436 CYRILLIC SMALL LETTER ZHE
"\ Xe7" => "\ xd0 \ xb7", # 0x0437 CYRILLIC SMALL LETTER ZE
"\ Xe8" => "\ xd0 \ xb8", # 0x0438 CYRILLIC SMALL LETTER I
"\ Xe9" => "\ xd0 \ xb9", # 0x0439 CYRILLIC SMALL LETTER SHORT I
"\ Xea" => "\ xd0 \ xba", # 0x043a CYRILLIC SMALL LETTER KA
"\ Xeb" => "\ xd0 \ xbb", # 0x043b CYRILLIC SMALL LETTER EL
"\ Xec" => "\ xd0 \ xbc", # 0x043c CYRILLIC SMALL LETTER EM
"\ Xed" => "\ xd0 \ xbd", # 0x043d CYRILLIC SMALL LETTER EN
"\ Xee" => "\ xd0 \ xbe", # 0x043e CYRILLIC SMALL LETTER O
"\ Xef" => "\ xd0 \ xbf", # 0x043f CYRILLIC SMALL LETTER PE
"\ Xf0" => "\ xd1 \ x80", # 0x0440 CYRILLIC SMALL LETTER ER
"\ Xf1" => "\ xd1 \ x81", # 0x0441 CYRILLIC SMALL LETTER ES
"\ Xf2" => "\ xd1 \ x82", # 0x0442 CYRILLIC SMALL LETTER TE
"\ Xf3" => "\ xd1 \ x83", # 0x0443 CYRILLIC SMALL LETTER U
"\ Xf4" => "\ xd1 \ x84", # 0x0444 CYRILLIC SMALL LETTER EF
"\ Xf5" => "\ xd1 \ x85", # 0x0445 CYRILLIC SMALL LETTER HA
"\ Xf6" => "\ xd1 \ x86", # 0x0446 CYRILLIC SMALL LETTER TSE
"\ Xf7" => "\ xd1 \ x87", # 0x0447 CYRILLIC SMALL LETTER CHE
"\ Xf8" => "\ xd1 \ x88", # 0x0448 CYRILLIC SMALL LETTER SHA
"\ Xf9" => "\ xd1 \ x89", # 0x0449 CYRILLIC SMALL LETTER SHCHA
"\ Xfa" => "\ xd1 \ x8a", # 0x044a CYRILLIC SMALL LETTER HARD SIGN
"\ Xfb" => "\ xd1 \ x8b", # 0x044b CYRILLIC SMALL LETTER YERU
"\ Xfc" => "\ xd1 \ x8c", # 0x044c CYRILLIC SMALL LETTER SOFT SIGN
"\ Xfd" => "\ xd1 \ x8d", # 0x044d CYRILLIC SMALL LETTER E
"\ Xfe" => "\ xd1 \ x8e", # 0x044e CYRILLIC SMALL LETTER YU
"\ Xff" => "\ xd1 \ x8f", # 0x044f CYRILLIC SMALL LETTER YA
);
return strtr ($ str, $ trans);
}
function safe_request ($ arr, $ pat) {
if (is_array ($ arr)) {
foreach ($ arr as $ n => $ v) {
if (is_array ($ n)) safe_request ($ n);
else {
if (is_utf8 ($ arr [$ n])) $ arr [$ n] = trim ($ arr [$ n]);
else $ arr [$ n] = cp1259_to_utf8 (trim ($ arr [$ n]));
foreach ($ pat as $ value) {$ arr [$ n] = preg_replace ("/ $ value / imu", "", $
arr [$ n]);}
}}}}
safe_request ($ _POST, $ cut_pattern);
safe_request ($ _GET, $ cut_pattern);
safe_request ($ _REQUEST, $ cut_pattern);
/ / Header ("Content-Type: text / html; charset = utf-8");
ob_start ();
?>

Вам также может понравиться