00001 <?php
00002
00015
00016
00017
00018 class String {
00022 function init() {
00023 $clientCharset = strtolower(Config::getVar('i18n', 'client_charset'));
00024
00025
00026 $PCRE_UTF8 = '';
00027 if ($clientCharset == 'utf-8' && String::hasPCREUTF8()) {
00028 $PCRE_UTF8 = 'u';
00029 }
00030
00031
00032
00033 if (String::hasMBString()) {
00034
00035 define('ENABLE_MBSTRING', 1);
00036
00037
00038 ini_set('mbstring.internal_encoding', $clientCharset);
00039 if ($clientCharset == 'utf-8') {
00040 ini_set('mbstring.substitute_character', '12307');
00041 }
00042
00043
00044 }
00045
00046
00047 define('PCRE_UTF8', $PCRE_UTF8);
00048 }
00049
00056 function hasMBString() {
00057 return (
00058 function_exists('mb_strlen') &&
00059 function_exists('mb_strpos') &&
00060 function_exists('mb_strrpos') &&
00061 function_exists('mb_substr') &&
00062 function_exists('mb_strtolower') &&
00063 function_exists('mb_strtoupper') &&
00064 function_exists('mb_substr_count') &&
00065 function_exists('mb_send_mail')
00066 );
00067 }
00068
00073 function hasPCREUTF8() {
00074
00075
00076 if (@preg_match('//u', '')) {
00077 return true;
00078 } else {
00079 return false;
00080 }
00081 }
00082
00083
00084
00085
00086
00087
00091 function strlen($string) {
00092 if (defined('ENABLE_MBSTRING')) {
00093 return mb_strlen($string);
00094 } else {
00095 return strlen($string);
00096 }
00097 }
00098
00102 function strpos($haystack, $needle, $offset = 0) {
00103 if (defined('ENABLE_MBSTRING')) {
00104 return mb_strpos($haystack, $needle, $offset);
00105 } else {
00106 return strpos($haystack, $needle, $offset);
00107 }
00108 }
00109
00113 function strrpos($haystack, $needle) {
00114 if (defined('ENABLE_MBSTRING')) {
00115 return mb_strrpos($haystack, $needle);
00116 } else {
00117 return strrpos($haystack, $needle);
00118 }
00119 }
00120
00124 function substr($string, $start, $length = null) {
00125 if (defined('ENABLE_MBSTRING')) {
00126 $substr = 'mb_substr';
00127 } else {
00128 $substr = 'substr';
00129 }
00130 if (isset($length)) {
00131 return $substr($string, $start, $length);
00132 } else {
00133 return $substr($string, $start);
00134 }
00135 }
00136
00140 function strtolower($string) {
00141 if (defined('ENABLE_MBSTRING')) {
00142 return mb_strtolower($string);
00143 } else {
00144 return strtolower($string);
00145 }
00146 }
00147
00151 function strtoupper($string) {
00152 if (defined('ENABLE_MBSTRING')) {
00153 return mb_strtoupper($string);
00154 } else {
00155 return strtolower($string);
00156 }
00157 }
00158
00162 function substr_count($haystack, $needle) {
00163 if (defined('ENABLE_MBSTRING')) {
00164 return mb_substr_count($haystack, $needle);
00165 } else {
00166 return substr_count($haystack, $needle);
00167 }
00168 }
00169
00173 function encode_mime_header($string) {
00174 if (defined('ENABLE_MBSTRING')) {
00175 return mb_encode_mimeheader($string, ini_get('mbstring.internal_encoding'), 'B', MAIL_EOL);
00176 } else {
00177 return $string;
00178 }
00179 }
00180
00184 function mail($to, $subject, $message, $additional_headers = '', $additional_parameters = '') {
00185
00186
00187 if (empty($additional_parameters)) {
00188 return mail($to, $subject, $message, $additional_headers);
00189 } else {
00190 return mail($to, $subject, $message, $additional_headers, $additional_parameters);
00191 }
00192 }
00193
00194
00195
00196
00197
00198
00202 function regexp_quote($string, $delimiter = '/') {
00203 return preg_quote($string, $delimiter);
00204 }
00205
00209 function regexp_grep($pattern, $input) {
00210 $pattern .= PCRE_UTF8;
00211 $input = String::utf8Clean($input);
00212 return preg_grep($pattern, $input);
00213 }
00214
00218 function regexp_match($pattern, $subject) {
00219 $pattern .= PCRE_UTF8;
00220 $subject = String::utf8Clean($subject);
00221 return preg_match($pattern, $subject);
00222 }
00223
00227 function regexp_match_get($pattern, $subject, &$matches) {
00228
00229 $pattern .= PCRE_UTF8;
00230 $subject = String::utf8Clean($subject);
00231 return preg_match($pattern, $subject, $matches);
00232 }
00233
00237 function regexp_match_all($pattern, $subject, &$matches) {
00238 $pattern .= PCRE_UTF8;
00239 $subject = String::utf8Clean($subject);
00240 return preg_match_all($pattern, $subject, $matches);
00241 }
00242
00246 function regexp_replace($pattern, $replacement, $subject, $limit = -1) {
00247 $pattern .= PCRE_UTF8;
00248 $subject = String::utf8Clean($subject);
00249 return preg_replace($pattern, $replacement, $subject, $limit);
00250 }
00251
00255 function regexp_replace_callback($pattern, $callback, $subject, $limit = -1) {
00256 $pattern .= PCRE_UTF8;
00257 $subject = String::utf8Clean($subject);
00258 return preg_replace_callback($pattern, $callback, $subject, $limit);
00259 }
00260
00264 function regexp_split($pattern, $subject, $limit = -1) {
00265 $pattern .= PCRE_UTF8;
00266 $subject = String::utf8Clean($subject);
00267 return preg_split($pattern, $subject, $limit);
00268 }
00269
00273 function mime_content_type($filename) {
00274 if (function_exists('mime_content_type')) {
00275 return mime_content_type($filename);
00276 } elseif (function_exists('finfo_open')) {
00277 static $fi;
00278 if (!isset($fi)) {
00279 $fi = finfo_open(FILEINFO_MIME, Config::getVar('finfo', 'mime_database_path'));
00280 }
00281 if ($fi !== false) {
00282 return strtok(finfo_file($fi, $filename), ' ;');
00283 }
00284 }
00285
00286
00287 $f = escapeshellarg($filename);
00288 $result = trim(`file --brief --mime $f`);
00289
00290 if (($i = strpos($result, ';')) !== false) {
00291 $result = trim(substr($result, 0, $i));
00292 }
00293 return $result;
00294 }
00295
00296
00303 function stripUnsafeHtml($input) {
00304
00305
00306
00307 $allowedHtml = Config::getVar('security', 'allowed_html');
00308 if ($allowedHtml == '') $allowedHtml = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <b> <i> <u> <img> <sup> <sub> <br> <p>';
00309
00310 $html = strip_tags($input, $allowedHtml);
00311
00312
00313 $html = preg_replace('/&#(x0*20|0*32);?/i', ' ', $html);
00314
00315
00316 $html = preg_replace('/&#x?0*([9A-D]|1[0-3]);/i', ' ', $html);
00317 $html = preg_replace('/&#x?0*[9A-D]([^0-9A-F]|$)/i', ' \\1', $html);
00318 $html = preg_replace('/�*(9|1[0-3])([^0-9]|$)/i', ' \\2', $html);
00319
00320
00321 $html = preg_replace('/&#x?0*[0-9A-F]{6,};?/i', ' ', $html);
00322
00323
00324
00325
00326 $preg = '/((�*61;?|�*3D;?|=)|'
00327 . '((u|�*85;?|�*55;?|�*117;?|�*75;?)\s*'
00328 . '(r|�*82;?|�*52;?|�*114;?|�*72;?)\s*'
00329 . '(l|�*76;?|�*4c;?|�*108;?|�*6c;?)\s*'
00330 . '(\()))\s*'
00331 . '(�*34;?|�*22;?|"|�*39;?|�*27;?|\')?'
00332 . '[^>]*\s*'
00333 . '(s|�*83;?|�*53;?|�*115;?|�*73;?)\s*'
00334 . '(c|�*67;?|�*43;?|�*99;?|�*63;?)\s*'
00335 . '(r|�*82;?|�*52;?|�*114;?|�*72;?)\s*'
00336 . '(i|�*73;?|�*49;?|�*105;?|�*69;?)\s*'
00337 . '(p|�*80;?|�*50;?|�*112;?|�*70;?)\s*'
00338 . '(t|�*84;?|�*54;?|�*116;?|�*74;?)\s*'
00339 . '(:|�*58;?|�*3a;?)/i';
00340 $html = preg_replace($preg, '\1\8OJSCleaned', $html);
00341
00342
00343 $html = preg_replace('/([\s"\']+'
00344 . '(o|�*79;?|�*4f;?|�*111;?|�*6f;?)'
00345 . '(n|�*78;?|�*4e;?|�*110;?|�*6e;?)'
00346 . '\w+)\s*=/i', '\1OJSCleaned=', $html);
00347
00348 $pattern = array(
00349 '|<([^>]*)&{.*}([^>]*)>|',
00350 '|<([^>]*)mocha:([^>]*)>|i',
00351 '|<([^>]*)binding:([^>]*)>|i'
00352 );
00353 $replace = array('<&{;}\3>', '<\1OJSCleaned:\2>', '<\1OJSCleaned:\2>');
00354 $html = preg_replace($pattern, $replace, $html);
00355
00356 return $html;
00357 }
00358
00365 function isUTF8 ($str) {
00366
00367 return preg_match('%(?:
00368 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
00369 |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
00370 |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
00371 |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
00372 |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
00373 |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
00374 |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
00375 )+%xs', $str);
00376 }
00377
00384 function utf8Clean($str) {
00385
00386 $UTF8_BAD =
00387 '([\x00-\x7F]'. # ASCII (including control chars)
00388 '|[\xC2-\xDF][\x80-\xBF]'. # non-overlong 2-byte
00389 '|\xE0[\xA0-\xBF][\x80-\xBF]'. # excluding overlongs
00390 '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'. # straight 3-byte
00391 '|\xED[\x80-\x9F][\x80-\xBF]'. # excluding surrogates
00392 '|\xF0[\x90-\xBF][\x80-\xBF]{2}'. # planes 1-3
00393 '|[\xF1-\xF3][\x80-\xBF]{3}'. # planes 4-15
00394 '|\xF4[\x80-\x8F][\x80-\xBF]{2}'. # plane 16
00395 '|(.{1}))'; # invalid byte
00396
00397 ob_start();
00398 while (preg_match('/'.$UTF8_BAD.'/S', $str, $matches)) {
00399 if ( !isset($matches[2])) {
00400 echo $matches[0];
00401 }
00402 $str = substr($str,strlen($matches[0]));
00403 }
00404 $result = ob_get_contents();
00405 ob_end_clean();
00406 return $result;
00407 }
00408
00416 function code2utf ($num) {
00417 if ($num < 128) return chr($num);
00418 if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
00419 if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
00420 if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
00421 return '';
00422 }
00423
00430 function utf2html ($str) {
00431 $ret = "";
00432 $max = strlen($str);
00433 $last = 0;
00434
00435 for ($i=0; $i<$max; $i++) {
00436 $c = $str{$i};
00437 $c1 = ord($c);
00438 if ($c1>>5 == 6) {
00439 $ret .= substr($str, $last, $i-$last);
00440 $c1 &= 31;
00441 $c2 = ord($str{++$i});
00442 $c2 &= 63;
00443 $c2 |= (($c1 & 3) << 6);
00444 $c1 >>= 2;
00445 $ret .= "&#" . ($c1 * 0x100 + $c2) . ";";
00446 $last = $i+1;
00447 }
00448 elseif ($c1>>4 == 14) {
00449 $ret .= substr($str, $last, $i-$last);
00450 $c2 = ord($str{++$i});
00451 $c3 = ord($str{++$i});
00452 $c1 &= 15;
00453 $c2 &= 63;
00454 $c3 &= 63;
00455 $c3 |= (($c2 & 3) << 6);
00456 $c2 >>=2;
00457 $c2 |= (($c1 & 15) << 4);
00458 $c1 >>= 4;
00459 $ret .= '&#' . (($c1 * 0x10000) + ($c2 * 0x100) + $c3) . ';';
00460 $last = $i+1;
00461 }
00462 }
00463 $str=$ret . substr($str, $last, $i);
00464
00465 return $str;
00466 }
00467
00474 function html2utf($str) {
00475
00476 $str = strtr($str, String::getHTMLEntities());
00477
00478
00479 $str = String::regexp_replace('~&#x([0-9a-f]+);~ei', 'String::code2utf(hexdec("\\1"))', $str);
00480 $str = String::regexp_replace('~&#([0-9]+);~e', 'String::code2utf(\\1)', $str);
00481
00482 return $str;
00483 }
00484
00491 function html2ascii ($str) {
00492
00493 $entities = array(
00494 "~" => "~", " " => " ", "¡" => "!",
00495 "¦" => "|", "±" => "+/-", "²" => "2",
00496 "³" => "3", "´" => "'", "¹" => "1",
00497 "¼" => "1/4", "½" => "1/2", "¾" => "3/4",
00498 "¿" => "?", "À" => "A", "Á" => "A",
00499 "Â" => "A", "Ã" => "A", "Ä" => "A",
00500 "Å" => "A", "Æ" => "AE", "Ç" => "C",
00501 "È" => "E", "É" => "E", "Ê" => "E",
00502 "Ë" => "E", "Ì" => "I", "Í" => "I",
00503 "Î" => "I", "Ï" => "I", "Ð" => "D",
00504 "Ñ" => "N", "Ò" => "O", "Ó" => "O",
00505 "Ô" => "O", "Õ" => "O", "Ö" => "O",
00506 "×" => "x", "Ø" => "O", "Ù" => "U",
00507 "Ú" => "U", "Ü" => "U", "Ý" => "Y",
00508 "à" => "a", "á" => "a", "â" => "a",
00509 "ã" => "a", "ä" => "a", "å" => "a",
00510 "æ" => "ae", "ç" => "c", "è" => "e",
00511 "é" => "e", "ê" => "e", "ë" => "e",
00512 "ì" => "i", "í" => "i", "î" => "i",
00513 "ï" => "i", "ð" => "o", "ñ" => "n",
00514 "ò" => "o", "ó" => "o", "ô" => "o",
00515 "õ" => "o", "ö" => "o", "ø" => "o",
00516 "ù" => "u", "ú" => "u", "ü" => "u",
00517 "ý" => "y", "ÿ" => "y",
00518 "Ā" => "A", "ā" => "a", "Ă" => "A",
00519 "ă" => "a", "Ą" => "A", "ą" => "a",
00520 "Ć" => "C", "ć" => "c", "Ĉ" => "C",
00521 "ĉ" => "c", "Ċ" => "C", "ċ" => "c",
00522 "Č" => "C", "č" => "c", "Ď" => "D",
00523 "ď" => "d", "Đ" => "D", "đ" => "d",
00524 "Ē" => "E", "ē" => "e", "Ĕ" => "E",
00525 "ĕ" => "e", "Ė" => "E", "ė" => "e",
00526 "Ę" => "E", "ę" => "e", "Ě" => "E",
00527 "ě" => "e", "Ĝ" => "G", "ĝ" => "g",
00528 "Ğ" => "G", "ğ" => "g", "Ġ" => "G",
00529 "ġ" => "g", "Ģ" => "G", "ģ" => "g",
00530 "Ĥ" => "H", "ĥ" => "h", "Ħ" => "H",
00531 "ħ" => "h", "Ĩ" => "I", "ĩ" => "i",
00532 "Ī" => "I", "ī" => "i", "Ĭ" => "I",
00533 "ĭ" => "i", "Į" => "I", "į" => "i",
00534 "İ" => "I", "ı" => "i", "IJ" => "IJ",
00535 "ij" => "ij", "Ĵ" => "J", "ĵ" => "j",
00536 "Ķ" => "K", "ķ" => "k", "ĸ" => "K",
00537 "Ĺ" => "L", "ĺ" => "l", "Ļ" => "L",
00538 "ļ" => "l", "Ľ" => "L", "ľ" => "l",
00539 "Ŀ" => "L", "ŀ" => "L", "Ł" => "L",
00540 "ł" => "l", "Ń" => "N", "ń" => "n",
00541 "Ņ" => "N", "ņ" => "n", "Ň" => "N",
00542 "ň" => "n", "ʼn" => "n", "Ŋ" => "N",
00543 "ŋ" => "n", "Ō" => "O", "ō" => "o",
00544 "Ŏ" => "O", "ŏ" => "o", "Ő" => "O",
00545 "ő" => "o", "Œ" => "OE", "œ" => "oe",
00546 "Ŕ" => "R", "ŕ" => "r", "Ŗ" => "R",
00547 "ŗ" => "r", "Ř" => "R", "ř" => "r",
00548 "Ś" => "S", "ś" => "s", "Ŝ" => "S",
00549 "ŝ" => "s", "Ş" => "S", "ş" => "s",
00550 "Š" => "S", "š" => "s", "Ţ" => "T",
00551 "ţ" => "t", "Ť" => "T", "ť" => "t",
00552 "Ŧ" => "T", "ŧ" => "t", "Ũ" => "U",
00553 "ũ" => "u", "Ū" => "U", "ū" => "u",
00554 "Ŭ" => "U", "ŭ" => "u", "Ů" => "U",
00555 "ů" => "u", "Ű" => "U", "ű" => "u",
00556 "Ų" => "U", "ų" => "u", "Ŵ" => "W",
00557 "ŵ" => "w", "Ŷ" => "Y", "ŷ" => "y",
00558 "Ÿ" => "Y", "Ź" => "Z", "ź" => "z",
00559 "Ż" => "Z", "ż" => "z", "Ž" => "Z",
00560 "ž" => "z", "'" => "'", "ƒ" => "f",
00561 "-" => "-", "ˆ" => "^", "˜" => "~",
00562 " " => " ", " " => " ", " " => " ",
00563 "–" => "-", "—" => "--", "‘" => "'",
00564 "’" => "'", "‚" => ",", "“" => '"',
00565 "”" => '"', "„" => ",,", "•" => "*",
00566 "…" => "...", "‰" => "%o", "′" => "'",
00567 "″" => "''", "™" => "TM", "−" => "-",
00568 "∗" => "*", "∧" => "/\\", "∨" => "\/",
00569 "∼" => "~", "⋅" => "*", "Α" => "A",
00570 "Β" => "B", "Ε" => "E", "Ζ" => "Z",
00571 "Η" => "H", "Ι" => "|", "Κ" => "K",
00572 "Μ" => "M", "Ν" => "N", "Ο" => "O",
00573 "Ρ" => "P", "Τ" => "T", "Υ" => "Y",
00574 "Χ" => "X", "^" => "^", "ο" => "o",
00575 "ρ" => "p", "ς" => "?", "ϑ" => "?",
00576 "ϖ" => "?"
00577 );
00578
00579 return strtr($str, $entities);
00580 }
00581
00588 function cp1252ToEntities ($str) {
00589
00590 $cp1252 = array(
00591 "€" => "", "" => "",
00592 "‚" => "‚", "ƒ" => "ƒ",
00593 "„" => "„", "…" => "…",
00594 "†" => "†", "‡" => "‡",
00595 "ˆ" => "", "‰" => "‰",
00596 "Š" => "Š", "‹" => "‹",
00597 "Œ" => "Œ", "" => "",
00598 "Ž" => "", "" => "",
00599 "" => "", "‘" => "‘",
00600 "’" => "’", "“" => "“",
00601 "”" => "”", "•" => "•",
00602 "–" => "–", "—" => "—",
00603 "˜" => "˜", "™" => "™",
00604 "š" => "š", "›" => "›",
00605 "œ" => "œ", "" => "",
00606 "ž" => "", "Ÿ" => "Ÿ"
00607 );
00608
00609
00610 $cp1252["‚"] = "‘";
00611 $cp1252["„"] = "“";
00612 $cp1252["’"] = "’";
00613 $cp1252["”"] = "”";
00614
00615 return strtr($str, $cp1252);
00616 }
00617
00624 function getHTMLEntities () {
00625
00626 $html_entities = array(
00627 "Á" => "Á", "á" => "á", "Â" => "Â",
00628 "â" => "â", "´" => "´", "Æ" => "Æ",
00629 "æ" => "æ", "À" => "À", "à" => "à",
00630 "ℵ" => "ℵ","Α" => "Α", "α" => "α",
00631 "&" => "&", "∧" => "∧", "∠" => "∠",
00632 "'" => "'", "Å" => "Å", "å" => "å",
00633 "≈" => "≈", "Ã" => "Ã", "ã" => "ã",
00634 "Ä" => "Ä", "ä" => "ä", "„" => "„",
00635 "Β" => "Β", "β" => "β", "¦" => "¦",
00636 "•" => "•", "∩" => "∩", "Ç" => "Ç",
00637 "ç" => "ç", "¸" => "¸", "¢" => "¢",
00638 "Χ" => "Χ", "χ" => "χ", "ˆ" => "^",
00639 "♣" => "♣", "≅" => "≅", "©" => "©",
00640 "↵" => "↵", "∪" => "∪", "¤" => "¤",
00641 "†" => "†","‡" => "‡", "↓" => "↓",
00642 "⇓" => "⇓", "°" => "°", "Δ" => "Δ",
00643 "δ" => "δ", "♦" => "♦", "÷" => "÷",
00644 "É" => "É", "é" => "é", "Ê" => "Ê",
00645 "ê" => "ê", "È" => "È", "è" => "è",
00646 "∅" => "∅", " " => " ", " " => " ",
00647 "Ε" => "Ε","ε" => "ε","≡" => "≡",
00648 "Η" => "Η", "η" => "η", "Ð" => "Ð",
00649 "ð" => "ð", "Ë" => "Ë", "ë" => "ë",
00650 "€" => "€", "∃" => "∃", "ƒ" => "ƒ",
00651 "∀" => "∀","½" => "½", "¼" => "¼",
00652 "¾" => "¾", "⁄" => "⁄", "Γ" => "Γ",
00653 "γ" => "γ", "≥" => "≥", ">" => ">",
00654 "↔" => "↔", "⇔" => "⇔", "♥" => "♥",
00655 "…" => "…","Í" => "Í", "í" => "í",
00656 "Î" => "Î", "î" => "î", "¡" => "¡",
00657 "Ì" => "Ì", "ì" => "ì", "ℑ" => "ℑ",
00658 "∞" => "∞", "∫" => "∫", "Ι" => "Ι",
00659 "ι" => "ι", "¿" => "¿", "∈" => "∈",
00660 "Ï" => "Ï", "ï" => "ï", "Κ" => "Κ",
00661 "κ" => "κ", "Λ" => "Λ", "λ" => "λ",
00662 "⟨" => "〈", "«" => "«", "←" => "←",
00663 "⇐" => "⇐", "⌈" => "⌈",
00664 "“" => "“", "≤" => "≤", "⌊" => "⌊",
00665 "∗" => "∗","◊" => "◊", "‎" => "‎",
00666 "‹" => "‹","‘" => "‘", "<" => "<",
00667 "¯" => "¯", "—" => "—", "µ" => "µ",
00668 "·" => "·", "−" => "-", "Μ" => "Μ",
00669 "μ" => "μ", "∇" => "∇", " " => " ",
00670 "–" => "–", "≠" => "≠", "∋" => "∋",
00671 "¬" => "¬", "∉" => "∉", "⊄" => "⊄",
00672 "Ñ" => "Ñ", "ñ" => "ñ", "Ν" => "Ν",
00673 "ν" => "ν", "Ó" => "Ó", "ó" => "ó",
00674 "Ô" => "Ô", "ô" => "ô", "Œ" => "Œ",
00675 "œ" => "œ", "Ò" => "Ò", "ò" => "ò",
00676 "‾" => "‾", "Ω" => "Ω", "ω" => "ω",
00677 "Ο" => "Ο","ο" => "ο","⊕" => "⊕",
00678 "∨" => "∨", "ª" => "ª", "º" => "º",
00679 "Ø" => "Ø", "ø" => "ø", "Õ" => "Õ",
00680 "õ" => "õ", "⊗" => "⊗","Ö" => "Ö",
00681 "ö" => "ö", "¶" => "¶", "∂" => "∂",
00682 "‰" => "‰","⊥" => "⊥", "Φ" => "Φ",
00683 "φ" => "φ", "Π" => "Π", "π" => "π",
00684 "ϖ" => "ϖ", "±" => "±", "£" => "£",
00685 "′" => "′", "″" => "″", "∏" => "∏",
00686 "∝" => "∝", "Ψ" => "Ψ", "ψ" => "ψ",
00687 """ => """, "√" => "√", "⟩" => "〉",
00688 "»" => "»", "→" => "→", "⇒" => "⇒",
00689 "⌉" => "⌉", "”" => "”", "ℜ" => "ℜ",
00690 "®" => "®", "⌋" => "⌋","Ρ" => "Ρ",
00691 "ρ" => "ρ", "‏" => "‏", "›" => "›",
00692 "’" => "’", "‚" => "‚", "Š" => "Š",
00693 "š" => "š", "⋅" => "⋅", "§" => "§",
00694 "­" => "­", "Σ" => "Σ", "σ" => "σ",
00695 "ς" => "ς", "∼" => "∼", "♠" => "♠",
00696 "⊂" => "⊂", "⊆" => "⊆", "∑" => "∑",
00697 "¹" => "¹", "²" => "²", "³" => "³",
00698 "⊃" => "⊃", "⊇" => "⊇", "ß" => "ß",
00699 "Τ" => "Τ", "τ" => "τ", "∴" => "∴",
00700 "Θ" => "Θ", "θ" => "θ", "ϑ" => "ϑ",
00701 " " => " ","Þ" => "Þ", "þ" => "þ",
00702 "˜" => "~", "×" => "×", "™" => "™",
00703 "Ú" => "Ú", "ú" => "ú", "↑" => "↑",
00704 "⇑" => "⇑", "Û" => "Û", "û" => "û",
00705 "Ù" => "Ù", "ù" => "ù", "¨" => "¨",
00706 "ϒ" => "ϒ", "Υ" => "Υ","υ" => "υ",
00707 "Ü" => "Ü", "ü" => "ü", "℘" => "℘",
00708 "Ξ" => "Ξ", "ξ" => "ξ", "Ý" => "Ý",
00709 "ý" => "ý", "¥" => "¥", "ÿ" => "ÿ",
00710 "Ÿ" => "Ÿ", "Ζ" => "Ζ", "ζ" => "ζ",
00711 "‍" => "‍", "‌" => "‌"
00712 );
00713
00714 return $html_entities;
00715 }
00716
00721 function fputcsv(&$handle, $fields = array(), $delimiter = ',', $enclosure = '"') {
00722
00723 if (function_exists('fputcsv')) {
00724 return fputcsv($handle, $fields, $delimiter, $enclosure);
00725 }
00726 $str = '';
00727 $escape_char = '\\';
00728 foreach ($fields as $value) {
00729 if ( strpos($value, $delimiter) !== false ||
00730 strpos($value, $enclosure) !== false ||
00731 strpos($value, "\n") !== false ||
00732 strpos($value, "\r") !== false ||
00733 strpos($value, "\t") !== false ||
00734 strpos($value, ' ') !== false
00735 ) {
00736 $str2 = $enclosure;
00737 $escaped = 0;
00738 $len = strlen($value);
00739 for ($i=0; $i<$len; $i++) {
00740 if ($value[$i] == $escape_char) $escaped = 1;
00741 elseif (!$escaped && $value[$i] == $enclosure) $str2 .= $enclosure;
00742 else $escaped = 0;
00743 $str2 .= $value[$i];
00744 }
00745 $str2 .= $enclosure;
00746 $str .= $str2 . $delimiter;
00747 } else {
00748 $str .= $value . $delimiter;
00749 }
00750 }
00751 $str = substr($str, 0, -1);
00752 $str .= "\n";
00753 return fwrite($handle, $str);
00754 }
00755 }
00756
00757 ?>