当前位置: 首页>>代码示例>>PHP>>正文


PHP utf8_is_ascii函数代码示例

本文整理汇总了PHP中utf8_is_ascii函数的典型用法代码示例。如果您正苦于以下问题:PHP utf8_is_ascii函数的具体用法?PHP utf8_is_ascii怎么用?PHP utf8_is_ascii使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了utf8_is_ascii函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _preSaveEntry

 protected function _preSaveEntry(array &$entry, array $data, $action)
 {
     $entry = array('name' => iaUtil::checkPostParam('name'), 'item' => iaUtil::checkPostParam('item'), 'collapsible' => iaUtil::checkPostParam('collapsible'), 'collapsed' => iaUtil::checkPostParam('collapsed'), 'tabview' => iaUtil::checkPostParam('tabview'), 'tabcontainer' => iaUtil::checkPostParam('tabcontainer'));
     iaUtil::loadUTF8Functions('ascii', 'bad', 'validation');
     if (iaCore::ACTION_ADD == $action) {
         if (!utf8_is_ascii($entry['name'])) {
             $this->addMessage('ascii_required');
         } else {
             $entry['name'] = strtolower($entry['name']);
         }
         if (!$this->getMessages() && !preg_match('/^[a-z0-9\\-_]{2,50}$/', $entry['name'])) {
             $this->addMessage('name_is_incorrect');
         }
         if (empty($data['item'])) {
             $this->addMessage('at_least_one_item_should_be_checked');
         }
         $entry['order'] = $this->_iaDb->getMaxOrder(iaField::getTableGroups()) + 1;
     }
     foreach ($this->_iaCore->languages as $code => $language) {
         if ($data['titles'][$code]) {
             if (!utf8_is_valid($data['titles'][$code])) {
                 $data['titles'][$code] = utf8_bad_replace($data['titles'][$code]);
             }
         } else {
             $this->addMessage($language['title'] . ': ' . iaLanguage::get('title_incorrect'), false);
         }
         if ($data['description'][$code]) {
             if (!utf8_is_valid($data['description'][$code])) {
                 $data['description'][$code] = utf8_bad_replace($data['description'][$code]);
             }
         }
     }
     return !$this->getMessages();
 }
开发者ID:TalehFarzaliey,项目名称:subrion,代码行数:34,代码来源:fieldgroups.php

示例2: encode_mail_text

function encode_mail_text($str)
{
    if (utf8_is_ascii($str)) {
        return $str;
    }
    return '=?UTF-8?B?' . base64_encode($str) . '?=';
}
开发者ID:rakete,项目名称:affenbande-fluxbb,代码行数:7,代码来源:email.php

示例3: titleAlias

 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;
 }
开发者ID:kreativmind,项目名称:subrion,代码行数:13,代码来源:ia.admin.blog.php

示例4: url

 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;
 }
开发者ID:nicefirework,项目名称:subrion-lyrics,代码行数:20,代码来源:ia.admin.artist.php

示例5: 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;
 }
开发者ID:nicefirework,项目名称:subrion-lyrics,代码行数:20,代码来源:ia.admin.lyric.php

示例6:

     if (!$member_id) {
         $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'];
开发者ID:nicefirework,项目名称:subrion-lyrics,代码行数:31,代码来源:albums.php

示例7: redirect

 /**
  * Redirect to another URL.
  *
  * If the headers have not been sent the redirect will be accomplished using a "301 Moved Permanently"
  * or "303 See Other" code in the header pointing to the new location. If the headers have already been
  * sent this will be accomplished using a JavaScript statement.
  *
  * @param   string   $url     The URL to redirect to. Can only be http/https URL.
  * @param   integer  $status  The HTTP 1.1 status code to be provided. 303 is assumed by default.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function redirect($url, $status = 303)
 {
     // Import library dependencies.
     jimport('phputf8.utils.ascii');
     // Check for relative internal links.
     if (preg_match('#^index\\.php#', $url)) {
         // We changed this from "$this->get('uri.base.full') . $url" due to the inability to run the system tests with the original code
         $url = JUri::base() . $url;
     }
     // Perform a basic sanity check to make sure we don't have any CRLF garbage.
     $url = preg_split("/[\r\n]/", $url);
     $url = $url[0];
     /*
      * Here we need to check and see if the URL is relative or absolute.  Essentially, do we need to
      * prepend the URL with our base URL for a proper redirect.  The rudimentary way we are looking
      * at this is to simply check whether or not the URL string has a valid scheme or not.
      */
     if (!preg_match('#^[a-z]+\\://#i', $url)) {
         // Get a JUri instance for the requested URI.
         $uri = JUri::getInstance($this->get('uri.request'));
         // Get a base URL to prepend from the requested URI.
         $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         // We just need the prefix since we have a path relative to the root.
         if ($url[0] == '/') {
             $url = $prefix . $url;
         } else {
             $parts = explode('/', $uri->toString(array('path')));
             array_pop($parts);
             $path = implode('/', $parts) . '/';
             $url = $prefix . $path . $url;
         }
     }
     // If the headers have already been sent we need to send the redirect statement via JavaScript.
     if ($this->checkHeadersSent()) {
         echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
     } else {
         // We have to use a JavaScript redirect here because MSIE doesn't play nice with utf-8 URLs.
         if ($this->client->engine == JApplicationWebClient::TRIDENT && !utf8_is_ascii($url)) {
             $html = '<html><head>';
             $html .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->charSet . '" />';
             $html .= '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script>';
             $html .= '</head><body></body></html>';
             echo $html;
         } else {
             // Check if we have a boolean for the status variable for compatability with old $move parameter
             // @deprecated 4.0
             if (is_bool($status)) {
                 $status = $status ? 301 : 303;
             }
             // Now check if we have an integer status code that maps to a valid redirect. If we don't then set a 303
             // @deprecated 4.0 From 4.0 if no valid status code is given a InvalidArgumentException will be thrown
             if (!is_int($status) || is_int($status) && !isset($this->responseMap[$status])) {
                 $status = 303;
             }
             // All other cases use the more efficient HTTP header for redirection.
             $this->header($this->responseMap[$status]);
             $this->header('Location: ' . $url);
             $this->header('Content-Type: text/html; charset=' . $this->charSet);
         }
     }
     // Close the application after the redirect.
     $this->close();
 }
开发者ID:hsc17,项目名称:joomla-cms,代码行数:77,代码来源:web.php

示例8: testUtf8IsAscii

 /**
  * @dataProvider providerUtf8IsAscii
  */
 public function testUtf8IsAscii($ord, $rv)
 {
     $this->assertEquals(utf8_is_ascii($ord), $rv);
 }
开发者ID:protaskin,项目名称:utf8,代码行数:7,代码来源:Base.php

示例9: utf8_from_unicode

/**
 * Takes an array of integers representing the Unicode characters and returns
 * a UTF-8 string.
 *
 * @param  array $unicode The array of Unicode code points
 * @param  bool  $strict  Should the function throw an error if something goes wrong
 * @return string The UTF-8 encoded string or false on failure
 */
function utf8_from_unicode($unicode, $strict = false)
{
    $rv = '';
    $count = count($unicode);
    for ($i = 0; $i < $count; $i++) {
        $cp = $unicode[$i];
        if (utf8_is_ascii($cp)) {
            $rv .= chr($cp);
            continue;
        }
        if (!unicode_is_valid($cp)) {
            if ($strict) {
                $msg = unicode_is_surrogate($cp) ? 'Illegal surrogate in UTF-8' : 'Codepoint out of Unicode range';
                trigger_error(sprintf('utf8_from_unicode: %s at index: %d, value: 0x%X', $msg, $i, $cp));
                return false;
            }
            continue;
        }
        $seqlen = utf8_sequence_length($cp);
        $rv .= chr(utf8_encode_identifier($cp, $seqlen));
        $offset = $seqlen - 2;
        do {
            $rv .= chr(utf8_encode_trail($cp, $offset));
        } while ($offset--);
    }
    return $rv;
}
开发者ID:protaskin,项目名称:utf8,代码行数:35,代码来源:converting.php

示例10: _preSaveEntry

 protected function _preSaveEntry(array &$entry, array $data, $action)
 {
     $this->_iaCore->startHook('adminAddMemberValidation');
     $iaAcl = $this->_iaCore->factory('acl');
     $iaField = $this->_iaCore->factory('field');
     $fields = iaField::getAcoFieldsList(iaCore::ADMIN, $this->_itemName);
     // below is the hacky way to force the script to upload files to the appropriate user's folder
     // FIXME
     $activeUser = iaUsers::getIdentity(true);
     $_SESSION[iaUsers::SESSION_KEY] = array('id' => $this->getEntryId(), 'username' => $data['username']);
     list($entry, $error, $this->_messages, ) = $iaField->parsePost($fields, $entry);
     $_SESSION[iaUsers::SESSION_KEY] = $activeUser;
     //
     if ($iaAcl->isAccessible($this->getName(), 'usergroup')) {
         if (isset($data['usergroup_id'])) {
             $entry['usergroup_id'] = array_key_exists($data['usergroup_id'], $this->_userGroups) ? $data['usergroup_id'] : iaUsers::MEMBERSHIP_REGULAR;
         }
     } elseif (iaCore::ACTION_ADD == $action) {
         $entry['usergroup_id'] = iaUsers::MEMBERSHIP_REGULAR;
     }
     if ($error) {
         return false;
     }
     $stmt = '`email` = :email';
     if (iaCore::ACTION_EDIT == $action) {
         if (isset($entry['status']) && $entry['status'] == $this->_iaDb->one('status', iaDb::convertIds((int) $this->getEntryId()))) {
             unset($entry['status']);
         }
         $stmt .= ' AND `id` != ' . (int) $this->getEntryId();
     }
     if ($this->_iaDb->exists($stmt, $entry)) {
         $this->addMessage('error_duplicate_email');
     }
     if ($this->_iaDb->exists('`username` = :username AND `id` != :id', array('username' => $entry['username'], 'id' => $this->getEntryId()))) {
         $this->addMessage('username_already_taken');
     }
     if ($iaAcl->checkAccess($this->getName(), 'password') || iaCore::ACTION_ADD == $action) {
         $this->_password = trim($data['_password']);
         if ($this->_password || !empty($data['_password2'])) {
             $entry['password'] = $this->getHelper()->encodePassword($this->_password);
             iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
             if (empty($entry['password'])) {
                 $this->addMessage('error_password_empty');
             } elseif (!utf8_is_ascii($entry['password'])) {
                 $this->addMessage(iaLanguage::get('password') . ': ' . iaLanguage::get('ascii_required'));
             } elseif ($entry['password'] != $this->getHelper()->encodePassword($data['_password2'])) {
                 $this->addMessage('error_password_match');
             }
         }
     }
     if (empty($data['_password']) && iaCore::ACTION_ADD == $action) {
         $this->addMessage('error_password_empty');
     }
     return !$this->getMessages();
 }
开发者ID:nicefirework,项目名称:subrion,代码行数:55,代码来源:members.php

示例11: _getJsonUrl

 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);
 }
开发者ID:bohmszi,项目名称:kdbe_cms,代码行数:20,代码来源:pages.php

示例12: _redirect

    /**
     * Redirects user to a given URL
     *
     * Uses JavaScript redirection if headers are already sent. Otherwise sends a 303 header.
     *
     * @param $url string A fully qualified URL
     */
    protected function _redirect($url)
    {
        // Strip out any line breaks.
        $url = preg_split("/[\r\n]/", $url);
        $url = $url[0];

        // If the headers have been sent, then we cannot send an additional location header
        // so we will output a javascript redirect statement.
        if (headers_sent())
        {
            echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
        }
        else
        {
            jimport('phputf8.utils.ascii');

            $document   = JFactory::getDocument();
            $user_agent = null;

            if (isset($_SERVER['HTTP_USER_AGENT'])) {
                $user_agent = $_SERVER['HTTP_USER_AGENT'];
            }

            if ((stripos($user_agent, 'MSIE') !== false || stripos($user_agent, 'Trident') !== false)
                && !utf8_is_ascii($url))
            {
                // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
                echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />'
                    . '<script>document.location.href=\'' . htmlspecialchars($url) . '\';</script></head></html>';
            }
            else
            {
                // All other browsers, use the more efficient HTTP header method
                header('HTTP/1.1 303 See other');
                header('Location: ' . $url);
                header('Content-Type: text/html; charset=' . $document->getCharset());
            }
        }

        JFactory::getApplication()->close();
    }
开发者ID:kosmosby,项目名称:medicine-prof,代码行数:48,代码来源:document.php

示例13: utf8_get_last_char

/**
 * This function may return boolean false, but may also return a non-boolean 0
 * which evaluates to false. Use the === operator for testing the return value
 * of this function.
 *
 * @param  string $str The UTF-8 encoded string
 * @param  int    $i   The current position of the string
 * @param  int    $rcp If passed, this will be set to the Unicode code point
 *                     for the character
 * @return string The character or false on the start of the string
 */
function utf8_get_last_char($str, &$i = null, &$rcp = null)
{
    if ($i === null) {
        $i = strlen($str) - 1;
    }
    while (isset($str[$i])) {
        $n = $i--;
        // Save current position and move to the previous octet
        $char = $str[$n++];
        // Move to the next octet at once
        $ord = ord($char);
        if (utf8_is_ascii($ord)) {
            $rcp = $ord;
            return $char;
        }
        if (utf8_is_identifier($ord, $seqlen)) {
            $cp = utf8_decode_identifier($ord, $seqlen);
            $offset = $seqlen - 2;
            // Check for exists the last octet of the sequence at once
            if (!isset($str[$n + $offset])) {
                continue;
            }
            do {
                $ord = ord($str[$n]);
                if (!utf8_is_trail($ord)) {
                    continue 2;
                    // Skip this sequence
                }
                $cp |= utf8_decode_trail($ord, $offset);
                $char .= $str[$n++];
            } while ($offset--);
            if (unicode_is_valid($cp) && utf8_sequence_length($cp) == $seqlen) {
                $rcp = $cp;
                return $char;
            }
        }
    }
    return false;
}
开发者ID:protaskin,项目名称:utf8,代码行数:50,代码来源:base.php

示例14: is_ascii

 /**
  * Tests whether a string contains only 7bit ASCII bytes.
  *
  * You might use this to conditionally check whether a string needs handling as UTF-8 or not, potentially offering performance
  * benefits by using the native PHP equivalent if it's just ASCII e.g.;
  *
  * <code>
  * if (StringHelper::is_ascii($someString))
  * {
  *     // It's just ASCII - use the native PHP version
  *     $someString = strtolower($someString);
  * }
  * else
  * {
  *     $someString = StringHelper::strtolower($someString);
  * }
  * </code>
  *
  * @param   string  $str  The string to test.
  *
  * @return  boolean True if the string is all ASCII
  *
  * @since   1.3.0
  */
 public static function is_ascii($str)
 {
     return utf8_is_ascii($str);
 }
开发者ID:lyrasoft,项目名称:lyrasoft.github.io,代码行数:28,代码来源:StringHelper.php

示例15: is_ascii

 /**
  * Tests whether a string contains only 7bit ASCII bytes.
  * You might use this to conditionally check whether a string
  * needs handling as UTF-8 or not, potentially offering performance
  * benefits by using the native PHP equivalent if it's just ASCII e.g.;
  *
  * <code>
  * if (String::is_ascii($someString))
  * {
  *     // It's just ASCII - use the native PHP version
  *     $someString = strtolower($someString);
  * }
  * else
  * {
  *     $someString = String::strtolower($someString);
  * }
  * </code>
  *
  * @param   string  $str  The string to test.
  *
  * @return  boolean True if the string is all ASCII
  *
  * @since   1.3.0
  */
 public static function is_ascii($str)
 {
     if (!function_exists('utf8_is_ascii')) {
         require_once __DIR__ . '/phputf8/utils/ascii.php';
     }
     return utf8_is_ascii($str);
 }
开发者ID:SysBind,项目名称:joomla-cms,代码行数:31,代码来源:StringHelper.php


注:本文中的utf8_is_ascii函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。