function convert_to_utf8(&$str, $old_charset) { if (is_null($str) || $str == '') { return false; } $save = $str; // Replace literal entities (for non-UTF-8 compliant html_entity_encode) if (version_compare(PHP_VERSION, '5.0.0', '<') && $old_charset == 'ISO-8859-1' || $old_charset == 'ISO-8859-15') { $str = html_entity_decode($str, ENT_QUOTES, $old_charset); } if ($old_charset != 'UTF-8' && !seems_utf8($str)) { if (function_exists('iconv')) { $str = iconv(!empty($old_charset) ? $old_charset : 'ISO-8859-1', 'UTF-8', $str); } else { if (function_exists('mb_convert_encoding')) { $str = mb_convert_encoding($str, 'UTF-8', !empty($old_charset) ? $old_charset : 'ISO-8859-1'); } else { if ($old_charset == 'ISO-8859-1') { $str = utf8_encode($str); } } } } // Replace literal entities (for UTF-8 compliant html_entity_encode) if (version_compare(PHP_VERSION, '5.0.0', '>=')) { $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8'); } // Replace numeric entities $str = preg_replace_callback('%&#([0-9]+);%', 'utf8_callback_1', $str); $str = preg_replace_callback('%&#x([a-f0-9]+);%i', 'utf8_callback_2', $str); // Remove "bad" characters $str = remove_bad_characters($str); return $save != $str; }
function convert_to_utf8($str) { $old_charset = $_SESSION['old_charset']; if ($str === null || $str == '' || $old_charset == 'UTF-8') { return $str; } $save = $str; // Replace literal entities (for non-UTF-8 compliant html_entity_encode) if (version_compare(PHP_VERSION, '5.0.0', '<') && $old_charset == 'ISO-8859-1' || $old_charset == 'ISO-8859-15') { $str = html_entity_decode($str, ENT_QUOTES, $old_charset); } if ($old_charset != 'UTF-8' && !seems_utf8($str)) { if (function_exists('iconv')) { $str = iconv($old_charset == 'ISO-8859-1' ? 'WINDOWS-1252' : $old_charset, 'UTF-8', $str); } else { if (function_exists('mb_convert_encoding')) { $str = mb_convert_encoding($str, 'UTF-8', $old_charset == 'ISO-8859-1' ? 'WINDOWS-1252' : 'ISO-8859-1'); } else { if ($old_charset == 'ISO-8859-1') { $str = utf8_encode($str); } } } } // Replace literal entities (for UTF-8 compliant html_entity_encode) if (version_compare(PHP_VERSION, '5.0.0', '>=')) { $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8'); } // Replace numeric entities $str = preg_replace_callback('/&#([0-9]+);/', 'utf8_callback_1', $str); $str = preg_replace_callback('/&#x([a-f0-9]+);/i', 'utf8_callback_2', $str); // Remove "bad" characters $str = remove_bad_characters($str); return $str; //($save != $str); }
function forum_remove_bad_characters() { $_GET = remove_bad_characters($_GET); $_POST = remove_bad_characters($_POST); $_COOKIE['CakeCookie'] = remove_bad_characters($_COOKIE['CakeCookie']); $_REQUEST = remove_bad_characters($_REQUEST); }
function forum_remove_bad_characters() { $_GET = remove_bad_characters($_GET); $_POST = remove_bad_characters($_POST); $_COOKIE = remove_bad_characters($_COOKIE); $_REQUEST = remove_bad_characters($_REQUEST); }
*/ function remove_bad_characters() { global $bad_utf8_chars; $bad_utf8_chars = array("", "", "̷", "̸", "ᅟ", "ᅠ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "", "", "", "", "", "", "", "", " ", " ", " ", "ㅤ", "", "ᅠ", "", "", "", ""); function _remove_bad_characters($array) { global $bad_utf8_chars; return is_array($array) ? array_map('_remove_bad_characters', $array) : str_replace($bad_utf8_chars, '', $array); } $_GET = _remove_bad_characters($_GET); $_POST = _remove_bad_characters($_POST); $_COOKIE = _remove_bad_characters($_COOKIE); $_REQUEST = _remove_bad_characters($_REQUEST); } remove_bad_characters(); include 'PubMedAPI.php'; $PubMedAPI = new PubMedAPI(); if (isset($_GET['page'])) { $PubMedAPI->retstart = $PubMedAPI->retmax * ((int) $_GET['page'] - 1) + 1; } $results = $PubMedAPI->query($term, false); } ?> <?php if (!empty($results)) { ?> <p>Search results for <strong><?php echo urldecode($PubMedAPI->term); ?>