public function titleAlias($title) { $result = iaSanitize::tags($title); $this->iaCore->factory('util'); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); utf8_is_ascii($result) || ($result = utf8_to_ascii($result)); $result = preg_replace('#' . self::ALIAS_SUFFIX . '$#i', '', $result); $result = iaSanitize::alias($result); $result = substr($result, 0, 150); // the DB scheme applies this limitation $result .= self::ALIAS_SUFFIX; return $result; }
/** * Transcode a string * @param $string string String to transcode * @return string Result of transcoding */ function trans($string) { // detect existence of encoding conversion libraries $mbstring = function_exists('mb_convert_encoding'); $iconv = function_exists('iconv'); // don't do work unless we have to if (strtolower($this->fromEncoding) == strtolower($this->toEncoding)) { return $string; } // 'HTML-ENTITIES' is not a valid encoding for iconv, so transcode manually if ($this->toEncoding == 'HTML-ENTITIES' && !$mbstring) { // NB: old PHP versions may have issues with htmlentities() if (checkPhpVersion('5.2.3')) { // don't double encode added in PHP 5.2.3 return htmlentities($string, ENT_COMPAT, $this->fromEncoding, false); } else { return htmlentities($string, ENT_COMPAT, $this->fromEncoding); } } elseif ($this->fromEncoding == 'HTML-ENTITIES' && !$mbstring) { // NB: old PHP versions may have issues with html_entity_decode() if (checkPhpVersion('4.3.0')) { // multibyte character handling added in PHP 5.0.0 return html_entity_decode($string, ENT_COMPAT, $this->toEncoding); } else { // use built-in transcoding to UTF8 $string = String::html2utf($string); // make another pass to target encoding $this->fromEncoding = 'UTF-8'; return $this->trans($string); } // Special cases for transliteration ("down-sampling") } elseif ($this->translit && $iconv) { // use the iconv library to transliterate return iconv($this->fromEncoding, $this->toEncoding . '//TRANSLIT', $string); } elseif ($this->translit && $this->fromEncoding == "UTF-8" && $this->toEncoding == "ASCII") { // use the utf2ascii library require_once './lib/pkp/lib/phputf8/utf8_to_ascii.php'; return utf8_to_ascii($string); } elseif ($mbstring) { // use the mbstring library to transcode return mb_convert_encoding($string, $this->toEncoding, $this->fromEncoding); } elseif ($iconv) { // use the iconv library to transcode return iconv($this->fromEncoding, $this->toEncoding . '//IGNORE', $string); } else { // fail gracefully by returning the original string unchanged return $string; } }
public function url($action, $data = array(), $generate = false) { $data['action'] = $action; $data['alias'] = isset($data['artist_alias']) ? $data['artist_alias'] : $data['title_alias']; if (!isset($this->patterns[$action])) { $action = 'view'; } if ($generate) { $iaUtil = $iaCore->factory('core', 'util'); if (!defined('IA_NOUTF')) { iaUtf8::loadUTF8Core(); iaUtf8::loadUTF8Util('ascii', 'validation', 'bad', 'utf8_to_ascii'); } if (!utf8_is_ascii($data['alias'])) { $data['alias'] = $iaCore->convertStr(utf8_to_ascii($data['alias'])); } } $url = iaDb::printf($this->patterns[$action], $data); return self::get('url') . $url; }
public function url($action, $data = array(), $generate = false) { $data['action'] = $action; $data['alias'] = isset($data['genre_alias']) ? $data['genre_alias'] : $data['title_alias']; if (!isset($this->patterns[$action])) { $action = 'view'; } if ($generate) { iaCore::util(); if (!defined('IA_NOUTF')) { iaUtf8::loadUTF8Core(); iaUtf8::loadUTF8Util('ascii', 'validation', 'bad', 'utf8_to_ascii'); } if (!utf8_is_ascii($data['alias'])) { $data['alias'] = $iaCore->convertStr(utf8_to_ascii($data['alias'])); } } $url = iaDb::printf($this->patterns[$action], $data); return $this->iaCore->packagesData[self::PACKAGE_NAME]['url'] . $url; }
function toLatin1($str, $enc = "") { if (!preg_match("/[^\\w\\.\\-\\@\\!\\#\$\\%\\^\\&\\*\\?\\[\\]\\{\\}\\.\\+\\/]/", $str)) { return $str; } //echo "non latin char in name<BR>"; $orgNum = substr_count($str, "?"); // check utf require_once dirname(__FILE__) . "/lib/utf8_to_ascii/utf8_to_ascii.php"; $newString = utf8_to_ascii($str); $newNum = substr_count($newString, "?"); if ($newNum <= $orgNum) { // no extra ? were added, this was a valid utf string return $newString; } global $langEncodings, $nativeLanguage; if ($enc == "") { $enc = $langEncodings[$nativeLanguage]; } require_once dirname(__FILE__) . "/lib/ConvertCharset/ConvertCharset.class.php"; $NewEncoding = new ConvertCharset(); $str_utf8 = $NewEncoding->Convert($str, $enc, "utf-8", $Entities); return utf8_to_ascii($str_utf8); }
$error = true; $messages[] = iaLanguage::get('album_incorrect_account'); } else { $data['member_id'] = $member_id; } } else { $data['member_id'] = iaUsers::getIdentity()->id; } if (!defined('IA_NOUTF')) { iaUtf8::loadUTF8Core(); iaUtf8::loadUTF8Util('ascii', 'validation', 'bad', 'utf8_to_ascii'); } // validate title_alias $data['title_alias'] = !empty($_POST['title_alias']) ? $_POST['title_alias'] : $_POST['title']; if (!utf8_is_ascii($data['title_alias'])) { $data['title_alias'] = utf8_to_ascii($data['title_alias']); } $data['title_alias'] = iaSanitize::convertStr($data['title_alias']); // check for duplicate title_alias in case a new album is added or title_alias has been updated if (!isset($item['title_alias']) || isset($item['title_alias']) && $data['title_alias'] != $item['title_alias']) { if ($iaAlbum->existsAlias($data['title_alias'])) { $error = true; $messages[] = iaLanguage::get('album_already_exists'); } } if (!$error) { $iaCore->startHook("phpAdminBeforeAlbumSubmit"); if (!empty($_POST['artist'])) { $artist_info = $iaArtist->getArtistByTitle($_POST['artist']); $data['id_artist'] = $artist_info['id']; $data['artist_alias'] = $artist_info['title_alias'];
</div><!-- /header --> <div class="content"> <ul data-role="listview" data-split-icon="gear" data-split-theme="a" data-inset="true" class="list-view"> <?php if (!empty($app)) { foreach ($app as $key => $value) { $temp = json_decode($value['download_url'], TRUE); unset($temp['plist']); $k = array_keys($temp); ?> <li> <a href="<?php echo base_url('ung-dung/' . utf8_to_ascii($value['name']) . '-' . $value['id_game_app']); ?> .html"> <img src="<?php echo base_url($value['icon']); ?> " class="img-list-game-app"/> <h2><?php echo $value['name']; ?> </h2> <p id="info-game"><?php echo $value['count_download']; ?> tải | <?php echo $value['size'];
/** * Transliterates (strips accents) text. * * For example. ë becomes e. * * @static * @param $str The input string. * @return string The transliterated string. */ public static function transliterate($string) { return utf8_to_ascii($string); }
public function addinfo() { $this->load->library('form_validation'); $response['code'] = -1; $response['redirect'] = '/backend/wap_info/index'; $response['message']['title'] = ''; // $response['message']['type'] = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $arrParam = $this->input->post(NULL, TRUE); $Id = @$arrParam['id']; $this->form_validation->set_rules('title', 'title', 'callback_xss_check|trim|required'); $this->form_validation->set_message('required', 'Không được rỗng'); if ($this->form_validation->run() == TRUE) { // die(json_encode($arrParam)); $Params = array(); $Params['title'] = $this->security->xss_clean($arrParam['title']); $Params['alias'] = utf8_to_ascii($Params['title']); $Params['content'] = $arrParam['content']; if (empty($Id) === TRUE) { $this->load->library('session'); $this->m_backend->jqxInsert('info_wap', $Params); } else { $this->m_backend->jqxUpdate('info_wap', 'id', $Id, $Params); } $response['code'] = 0; } else { $badchars = array('<p>', '</p>'); $response['message']['title'] = trim(str_replace($badchars, '', form_error('title'))); $response['message']['content'] = trim(str_replace($badchars, '', form_error('type'))); $response['code'] = 1; } } end: echo json_encode($response); exit; }
<!-------------------------------------------------------------> <div class="content name-block"> <span>VIDEOS</span> </div> <div class="content"> <ul data-role="listview" data-split-icon="gear" data-split-theme="a" data-inset="true" class="list-view list-view-news-video"> <?php if (!empty($videos)) { foreach ($videos as $key => $value) { ?> <li> <div class="over-play"></div> <a href="<?php echo base_url('videos/' . utf8_to_ascii($value['name']) . '-' . $value['id_news_video']); ?> .html"> <img src="<?php echo base_url($value['image']); ?> "/> <h2><?php echo $value['name']; ?> </h2> <p id="descript-game"><?php echo limit_text($value['description'], 20);
/** * Tạo link không dấu để SEO * @author Nguyen Xuan Hung * @data 02.03.2011 */ function ascii_link($title = '', $char = '-') { $name = strtolower(utf8_to_ascii($title)); $name = preg_replace("/[^a-z0-9]/i", ' ', $name); // a-z - . space $name = preg_replace("/\\s{2,}/i", ' ', trim($name)); // Replace 2 or more space = 1 space $name = str_replace(' ', $char, $name); return $name; }
/** * Converts text to well-formed URL, replaces all non alpha-numeric / underscore symbols to separator * * @param string $string text to be converted * @param string $separator separator symbol used for the conversion * * @return string */ public static function alias($string, $separator = '-') { iaCore::instance()->factory('util')->loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); $string = html_entity_decode($string); $string = str_replace(array('&', "'"), array('and', ''), $string); $urlEncoded = false; if (!utf8_is_ascii($string)) { if (iaCore::instance()->get('alias_urlencode', false)) { $string = preg_replace('#[^0-9\\p{L}]+#ui', $separator, $string); $urlEncoded = true; } else { $string = utf8_to_ascii($string); } } $string = $urlEncoded ? $string : preg_replace('#[^a-z0-9_]+#i', $separator, $string); $string = trim($string, $separator); return $string; }
private function _getJsonUrl(array $params) { iaUtil::loadUTF8Functions('ascii', 'utf8_to_ascii'); $name = $params['name']; $name = utf8_is_ascii($name) ? $name : utf8_to_ascii($name); $name = preg_replace('#[^a-z0-9-_]#iu', '', $name); $url = $params['url']; $url = utf8_is_ascii($url) ? $url : utf8_to_ascii($url); $url = preg_replace('#[^a-z0-9-_]#iu', '', $url); $url = $url ? $url : $name; if (is_numeric($params['parent']) && $params['parent']) { $parentPage = $this->getById($params['parent']); $parentAlias = empty($parentPage['alias']) ? $parentPage['name'] . IA_URL_DELIMITER : $parentPage['alias']; $url = $parentAlias . (IA_URL_DELIMITER == substr($parentAlias, -1, 1) ? '' : IA_URL_DELIMITER) . $url; } $url .= $params['ext']; $exists = $this->_iaDb->exists('`alias` = :url AND `name` != :name', array('url' => $url, 'name' => $name)); $url = IA_URL . $url; return array('url' => $url, 'exists' => $exists); }
function upp_mangle_filename($file_name) { /* remove internal dots (cosmetical, it would be done by WP, but we need to display it :)*/ $ext = upp_findexts($file_name); $file_name = str_replace("." . $ext, "", $file_name); $file_name = str_replace(".", "", $file_name); // initial cleaning $file_name = str_replace("(", "", $file_name); $file_name = str_replace(")", "", $file_name); $file_name = str_replace("'", "", $file_name); $file_name = str_replace('"', "", $file_name); $file_name = str_replace(',', "", $file_name); // some language-based prefilter. props denis. $de_from = array('ä', 'ö', 'ü', 'ß', 'Ä', 'Ö', 'Ü'); $de_to = array('ae', 'oe', 'ue', 'ss', 'Ae', 'Oe', 'Ue'); $file_name = str_replace($de_from, $de_to, $file_name); $utf8ornot = get_option('uploadplus_utf8toascii'); if ($utf8ornot[0] == 1) { $file_name = utf8_to_ascii($file_name); } $file_name = $file_name . "." . $ext; $lettercase = get_option('uploadplus_case'); switch ($lettercase[0]) { case "1": $file_name = utf8_strtolower($file_name); break; case "2": $file_name = utf8_strtoupper($file_name); break; } $y = get_option('uploadplus_cleanlevel'); switch ($y[0]) { case "1": $file_name = ereg_replace("[^A-Za-z0-9._]", "-", $file_name); $file_name = utf8_ireplace("_", "-", $file_name); $file_name = utf8_ireplace(" ", "-", $file_name); $file_name = utf8_ireplace("%20", "-", $file_name); break; case "2": $file_name = ereg_replace("[^A-Za-z0-9._]", "", $file_name); $file_name = utf8_ireplace("_", "", $file_name); $file_name = utf8_ireplace("-", "", $file_name); $file_name = utf8_ireplace("%20", "", $file_name); break; case "3": $file_name = ereg_replace("[^A-Za-z0-9._]", "_", $file_name); $file_name = utf8_ireplace("-", "_", $file_name); $file_name = utf8_ireplace(" ", "_", $file_name); $file_name = utf8_ireplace("%20", "_", $file_name); break; } $sep = $y[0] == '1' ? "-" : ""; if (!$sep) { $sep = $y[0] == '3' ? "_" : ""; } $standard = get_option('uploadplus_prefix'); switch ($standard) { case "0": $file_name = date('d') . $sep . $file_name; break; case "1": $file_name = date('md') . $sep . $file_name; break; case "2": $file_name = date('ymd') . $sep . $file_name; break; case "3": $file_name = date('Ymd') . $sep . $file_name; break; case "4": $file_name = date('YmdHi') . $sep . $file_name; break; case "5": $file_name = date('YmdHis') . $sep . $file_name; break; case "6": $file_name = date('U') . $sep . $file_name; break; case "7": $file_name = mt_rand() . $sep . $file_name; break; case "8": $file_name = md5(mt_rand()) . $sep . $file_name; break; case "9": $file_name = str_replace(array(".", "_", "-", " "), $sep, utf8_to_ascii(get_bloginfo('name'))) . $sep . $file_name; break; case "A": $file_name = str_replace(array(".", "_", "-", " "), "", utf8_to_ascii(get_bloginfo('name'))) . $sep . $file_name; break; } return $file_name; }
public function action_search() { $params = $this->input->get(NULL, TRUE); $data = $this->m_wap->search($params['data']); $num_row = $this->m_wap->get_num_row('game_app', array('type' => 'app', 'status' => 'active', 'cate' => $params['cat'])); if (!empty($data)) { foreach ($data as $key => $value) { $temp = json_decode($value['download_url'], TRUE); unset($temp['plist']); $k = array_keys($temp); $class = 'a.click-download-game-' . $value['id_game_app']; $sub = 'ung-dung'; if ($value['type'] == 'game') { $sub = 'game'; } $result .= ' <li class="ui-li-has-alt ui-li-has-thumb"> <a href="' . base_url($sub . '/' . utf8_to_ascii($value['name']) . '-' . $value['id_game_app'] . '.html') . '" class="ui-btn"> <img src="' . base_url($value["icon"]) . '" /> <h2>' . $value['name'] . '</h2> <p id="info-game"> ' . $value["count_download"] . 'tải | ' . $value['size'] . ' kb</p> <p id="descript-game">' . limit_text($value["description"], 20) . '</p> </a> <a href="#purchase-app" data-rel="popup" onclick="abc' . $value['id_game_app'] . '();" data-position-to="window" data-transition="pop" aria-haspopup="true" aria-owns="purchase" aria-expanded="false" class="ui-btn ui-btn-icon-notext ui-icon-gear ui-btn-a" title=""></a> <div class="free-download">FREE</div> </li> <script> function abc' . $value['id_game_app'] . '(){ var _json = \'' . json_encode($k) . '\'; var _id_game = \'' . $value['id_game_app'] . '\' var _obj = JSON.parse(_json); var _html = ""; if (platform == "pc") { for (var key in _obj) { _html += \'<a target="_blank" href="' . base_url() . 'tai-game?id=\' + _id_game + \'&platform=\' + _obj[key] + \'" data-ajax="false"><button class="ui-bnt ui-btn ui-shadow ui-corner-all" style="text-transform: uppercase">\' + _obj[key] + \'</button></a>\'; $(\'.bnt-download-game\').html(_html); } }else{ $(\'#purchase-app\').remove(); for (var key in _obj) { if (_obj[key] == \'' . $_SESSION['platform'] . '\') { _html = \'' . base_url() . 'tai-game?id=\' + _id_game + \'&platform=\' + _obj[key]; if (confirm(\'Bạn có tải ứng dụng?\')) { window.open(_html); } } } } } </script> '; } } $array_result = array('isLoadmore' => check_last_page($offset, $num_row), 'html' => $result, 'page' => $params['page'] + 1); die(json_encode($array_result)); }
function transliterate($str, $enc) { // see this for hebraic-chinisee // http://www.derickrethans.nl/translit.php global $CONF_use_utf; if ($enc == 'gb2312') { // echo "#### $str $enc ##"; if (!$CONF_use_utf) { require_once dirname(__FILE__) . "/lib/ConvertCharset/convert_gb2312.php"; return gb2312_to_latin($str); } else { if (substr(phpversion(), 0, 1) >= 5) { require_once dirname(__FILE__) . "/lib/ConvertCharset/chinese/charset.class.php"; $gb2312_str = Charset::convert($str, 'utf-8', 'gb2312'); $str2 = Charset::PinYin($gb2312_str, 'gb2312'); // echo "^gb2312_str : $gb2312_str ^ "; // echo "^str2: $str2 ^ "; return $str2; } else { return $str; } } } require_once dirname(__FILE__) . "/lib/ConvertCharset/ConvertCharset.class.php"; require_once dirname(__FILE__) . "/lib/utf8_to_ascii/utf8_to_ascii.php"; // if $CONF_use_utf it means the $str is already in utf // so translitarate it directly if ($CONF_use_utf) { return utf8_to_ascii($str); } $NewEncoding = new ConvertCharset(); $str_utf8 = $NewEncoding->Convert($str, $enc, "utf-8", $Entities); return utf8_to_ascii($str_utf8); }
public static function strToAscii($title, $allowChars = "") { if (!function_exists("utf8_to_ascii")) { require_once Config::get('COMPONENTS_PATH') . "phputf8/utils/utf8_to_ascii.php"; } $title = utf8_to_ascii($title); $specialChars = array(' ', '\''); $normalChars = array('-', '-'); $stringMaxLength = 70; $newTitle = substr(preg_replace("#\\-\$#", '', preg_replace("#\\-+#", '-', strtolower(preg_replace("#[^A-Za-z0-9" . preg_quote($allowChars) . "]#", '-', str_replace($specialChars, $normalChars, htmlspecialchars_decode($title)))))), 0, $stringMaxLength); return $newTitle; }
/** * US-ASCII transliterations of Unicode text * @param $str string input string * @return string */ static function utf8_to_ascii($str) { require_once './lib/pkp/lib/phputf8/utf8_to_ascii.php'; return utf8_to_ascii($str); }
/** * US-ASCII transliterations of Unicode text * @param $str string input string * @return string */ function utf8_to_ascii($str) { require_once 'utf8_to_ascii.php'; return utf8_to_ascii($str); }
function sefUrlEncode($text, $level = 0, $and_replace = 'and') { $_this =& S2Router::getInstance(); if (isset($_this->__translit[$text])) { return $_this->__translit[$text]; } $translitText = str_replace(array('-', '&'), array(' ', $and_replace), $text); switch ($level) { case 0: case 1: $translitText = htmlentities(utf8_decode($translitText)); $translitText = preg_replace(array('/ß/', '/&(..)lig;/', '/&([aouAOU])uml;/', '/&(.)[^;]*;/'), array('ss', "\$1", "\$1" . 'e', "\$1"), $translitText); // remove any duplicate whitespace, and ensure characters are alphanumeric $translitText = preg_replace(array('/\\s+/'), array('-'), $translitText); $translitText = preg_replace(array('/[^A-Za-z0-9\\-]/'), array(''), $translitText); break; case 2: App::import('Lib', 'utf8_to_ascii', $this->app); $translitText = utf8_to_ascii($translitText, ''); break; } $_this->__translit[$text] = $translitText; return $translitText; }
$eol = php_sapi_name() == 'cli' ? "\n" : "<br>\n"; $out = utf8_to_ascii($out); if (preg_match('/(?:[^\\x00-\\x7F])/', $out) !== 1) { print "PASS: output is all ASCII{$eol}"; } else { print "FAIL: output still contains UTF-8{$eol}"; } exit; } if (isset($_GET['out']) && $_GET['out'] == 'ascii') { header('Content-Type: text/html; charset=US-ASCII'); } else { header('Content-Type: text/html; charset=UTF-8'); } if (isset($_GET['out']) && $_GET['out'] == 'ascii') { $out = utf8_to_ascii($out); } ?> <html> <head> <title>US-ASCII transliterations of Unicode text</title> </head> <body> <h1>US-ASCII transliterations of Unicode text</h1> <p><a href="?out=utf-8">Before</a> | <a href="?out=ascii">After</a> | <a href="?test">Test</a></p> <pre> <?php print htmlspecialchars($out); ?> </pre> </body>