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


PHP strcspn函数代码示例

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


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

示例1: load_class

 /**
  * @desc Called by the autoload engine to load a specific class must return true on success,
  * or false if class is not found
  * @param string $class_name - a class to load
  * @param bool $test_only - if true, do not actually load class, only check if it is present
  * @return bool
  */
 public function load_class($class_name, $test_only = false)
 {
     if (strcspn($class_name, "#=\"\\?*:/@|<>.\$") != strlen($class_name)) {
         die("Invalid class name: [{$class_name}]");
     }
     $prefix = $this->prefix;
     // check if the class belongs to our namespace:
     if (substr($class_name, 0, strlen($prefix)) == $prefix) {
         $class_name2 = substr($class_name, strlen($prefix));
     } else {
         return false;
     }
     $file = "{$this->path}/{$class_name}.class.php";
     if (!file_exists($file)) {
         $file = "{$this->path}/{$class_name2}.class.php";
     }
     if (file_exists($file)) {
         if (!$test_only) {
             include $file;
         }
         return true;
     }
     // Maybe this is an interface?
     $file = "{$this->path}/{$class_name}.interface.php";
     if (!file_exists($file)) {
         $file = "{$this->path}/{$class_name2}.interface.php";
     }
     if (file_exists($file)) {
         if (!$test_only) {
             include $file;
         }
         return true;
     }
     return false;
 }
开发者ID:laiello,项目名称:pkgmanager,代码行数:42,代码来源:pkgman_package.class.php

示例2: nextToken

 /**
  * Returns the next token from this tokenizer's string
  *
  * @param   bool delimiters default NULL
  * @return  string next token
  */
 public function nextToken($delimiters = null)
 {
     if (empty($this->_stack)) {
         // Read until we have either find a delimiter or until we have
         // consumed the entire content.
         do {
             $offset = strcspn($this->_buf, $delimiters ? $delimiters : $this->delimiters);
             if ($offset < strlen($this->_buf) - 1) {
                 break;
             }
             if (null === ($buf = $this->source->read())) {
                 break;
             }
             $this->_buf .= $buf;
         } while (true);
         if (!$this->returnDelims || $offset > 0) {
             $this->_stack[] = substr($this->_buf, 0, $offset);
         }
         $l = strlen($this->_buf);
         if ($this->returnDelims && $offset < $l) {
             $this->_stack[] = $this->_buf[$offset];
         }
         $offset++;
         $this->_buf = $offset < $l ? substr($this->_buf, $offset) : false;
     }
     return array_shift($this->_stack);
 }
开发者ID:xp-framework,项目名称:tokenize,代码行数:33,代码来源:TextTokenizer.class.php

示例3: getPositionFirstVowel

 public function getPositionFirstVowel($word)
 {
     if (empty($word) || !is_string($word)) {
         throw new \InvalidArgumentException(__FILE__ . ':' . __LINE__ . ': Invalid word, it must be a string, got :' . var_export($word, true));
     }
     return strcspn(strtolower($word), self::VOWEL);
 }
开发者ID:priscille-q,项目名称:pigLatinTranslator,代码行数:7,代码来源:Parser.php

示例4: getUserBytes

function getUserBytes($user)
{
    global $ipfw_offset;
    global $ipfw;
    global $UserBytes;
    $ipfw_rule = $ipfw_offset + $user;
    $RuleNum1 = 0;
    if (!count($UserBytes)) {
        $ftext = array();
        exec($ipfw . ' show', $ftext);
        for ($i = 0; $i < count($ftext); $i++) {
            $strTmp = trim($ftext[$i]);
            $len = strcspn($strTmp, " ");
            $RuleNum = substr($strTmp, 0, $len);
            $strTmp = trim(substr_replace($strTmp, " ", 0, $len));
            $len = strcspn($strTmp, " ");
            $CountPakets = substr($strTmp, 0, $len);
            $strTmp = trim(substr_replace($strTmp, " ", 0, $len));
            $len = strcspn($strTmp, " ");
            $CountBytes = substr($strTmp, 0, $len);
            if ($RuleNum1 != $RuleNum) {
                $RuleNum1 = $RuleNum;
                $UserBytes[$RuleNum] = $CountBytes;
            }
        }
    }
    return isset($UserBytes[$ipfw_rule]) ? $UserBytes[$ipfw_rule] : false;
}
开发者ID:nagyistoce,项目名称:lanmediaservice-lms-video-ce-1.x,代码行数:28,代码来源:shaper.php

示例5: getHostInfo

 public function getHostInfo($schema = '')
 {
     if ($this->_hostInfo === null) {
         if ($secure = $this->getIsSecureConnection()) {
             $http = 'https';
         } else {
             $http = 'http';
         }
         if (isset($_SERVER['HTTP_HOST'])) {
             $this->_hostInfo = $http . '://' . $_SERVER['HTTP_HOST'];
         } else {
             $this->_hostInfo = $http . '://' . $_SERVER['SERVER_NAME'];
             $port = $secure ? $this->getSecurePort() : $this->getPort();
             if ($port !== 80 && !$secure || $port !== 443 && $secure) {
                 $this->_hostInfo .= ':' . $port;
             }
         }
     }
     if ($schema !== '') {
         $secure = $this->getIsSecureConnection();
         if ($secure && $schema === 'https' || !$secure && $schema === 'http') {
             return $this->_hostInfo;
         }
         $port = $schema === 'https' ? $this->getSecurePort() : $this->getPort();
         if ($port !== 80 && $schema === 'http' || $port !== 443 && $schema === 'https') {
             $port = ':' . $port;
         } else {
             $port = '';
         }
         $pos = strpos($this->_hostInfo, ':');
         return $schema . substr($this->_hostInfo, $pos, strcspn($this->_hostInfo, ':', $pos + 1) + 1) . $port;
     } else {
         return $this->_hostInfo;
     }
 }
开发者ID:RandomCivil,项目名称:tiny-yii,代码行数:35,代码来源:CHttpRequest.php

示例6: match

 public function match($source, &$pos)
 {
     $sourceLength = strlen($source);
     for (; $pos < $sourceLength; $pos++) {
         $pos += strcspn($source, $this->firstChars, $pos);
         if ($pos == $sourceLength) {
             return false;
         }
         foreach ($this->stdTags as $tagIndex => $tag) {
             $this->tagLength = strlen($tag);
             if ($pos + $this->tagLength <= $sourceLength && substr_compare($source, $tag, $pos, $this->tagLength) === 0) {
                 $pos += $this->tagLength;
                 $this->tagIndex = $tagIndex;
                 $this->isStdTag = true;
                 return true;
             }
         }
         foreach ($this->userTags as $tagIndex => $tag) {
             $this->tagLength = strlen($tag);
             if ($pos + $this->tagLength <= $sourceLength && substr_compare($source, $tag, $pos, $this->tagLength) === 0) {
                 $pos += $this->tagLength;
                 $this->tagIndex = $tagIndex;
                 $this->isStdTag = false;
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:ljarray,项目名称:dbpedia,代码行数:29,代码来源:Matcher.php

示例7: export

 /**
  * Export a literal as an XPath expression
  *
  * @param  string $str Literal, e.g. "foo"
  * @return string      XPath expression, e.g. "'foo'"
  */
 public static function export($str)
 {
     // foo becomes 'foo'
     if (strpos($str, "'") === false) {
         return "'" . $str . "'";
     }
     // d'oh becomes "d'oh"
     if (strpos($str, '"') === false) {
         return '"' . $str . '"';
     }
     // This string contains both ' and ". XPath 1.0 doesn't have a mechanism to escape quotes,
     // so we have to get creative and use concat() to join chunks in single quotes and chunks
     // in double quotes
     $toks = [];
     $c = '"';
     $pos = 0;
     while ($pos < strlen($str)) {
         $spn = strcspn($str, $c, $pos);
         if ($spn) {
             $toks[] = $c . substr($str, $pos, $spn) . $c;
             $pos += $spn;
         }
         $c = $c === '"' ? "'" : '"';
     }
     return 'concat(' . implode(',', $toks) . ')';
 }
开发者ID:CryptArc,项目名称:TextFormatter,代码行数:32,代码来源:XPathHelper.php

示例8: parse_query

function parse_query($submitted_query)
{
    $query = explode(' ', $submitted_query);
    if (strcspn($query[0], '0123456789') == strlen($query[0])) {
        # One word book title (ie. Jacob, James, Matthew)
        $book = $query[0];
        $chapter = $query[1];
        if ($query[1] && strcspn($query[1], '0123456789') == strlen($query[1])) {
            # Two word book title (ie. Solomon's Song)
            $book .= ' ' . $query[1];
            $chapter = $query[2];
            if ($query[2] && strcspn($query[2], '0123456789') == strlen($query[2])) {
                # Three word book title (ie. Doctrine and Covenants, Words of Mormon)
                $book .= ' ' . $query[2];
                $chapter = $query[3];
            }
        }
    }
    if (strcspn($query[0], '0123456789') != strlen($query[0])) {
        # Book that starts with a number (ie. 1 Nephi, 2 Corinthians, 3 John)
        $book = $query[0] . ' ' . $query[1];
        $chapter = $query[2];
    }
    $get_verse = explode(':', $chapter);
    $result['book'] = $book;
    $result['chapter'] = $get_verse[0];
    $result['verse'] = $get_verse[1];
    return $result;
}
开发者ID:andrewheiss,项目名称:scriptures,代码行数:29,代码来源:getScriptureURL.php

示例9: _matchHttpAcceptLanguages

 /**
  * Tries to match the prefered language out of the http_accept_language string 
  * with one of the available languages.
  *
  * @private
  * @param httpAcceptLanguage the value of $_SERVER['HTTP_ACCEPT_LANGUAGE']
  * @return Returns returns prefered language or false if no language matched.
  */
 function _matchHttpAcceptLanguages(&$httpAcceptLanguage)
 {
     $acceptedLanguages = explode(',', $httpAcceptLanguage);
     $availableLanguages =& Locales::getAvailableLocales();
     $primaryLanguageMatch = '';
     // we iterate through the array of languages sent by the UA and test every single
     // one against the array of available languages
     foreach ($acceptedLanguages as $acceptedLang) {
         // clean the string and strip it down to the language value (remove stuff like ";q=0.3")
         $acceptedLang = substr($acceptedLang, 0, strcspn($acceptedLang, ';'));
         if (strlen($acceptedLang) > 2) {
             // cut to primary language
             $primaryAcceptedLang = substr($acceptedLang, 0, 2);
         } else {
             $primaryAcceptedLang = $acceptedLang;
         }
         // this is where we start to iterate through available languages
         foreach ($availableLanguages as $availableLang) {
             if (stristr($availableLang, $acceptedLang) !== false) {
                 // we have a exact language match
                 return $availableLang;
             } elseif (stristr($availableLang, $primaryAcceptedLang) !== false && $primaryLanguageMatch == '') {
                 // we found the first primary language match!
                 $primaryLanguageMatch = $availableLang;
             }
         }
     }
     // foreach
     if ($primaryLanguageMatch != '') {
         return $primaryLanguageMatch;
     } else {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:42,代码来源:summaryaction.class.php

示例10: parseInput

 protected function parseInput($native, &$pos)
 {
     $hasDelimiters = $angleDelimiter = $singleOpen = false;
     if ('<' === ($char = $this->nextChar($native, $pos)) || '(' === $char) {
         $hasDelimiters = true;
         if ('<' === $char) {
             $angleDelimiter = true;
         } else {
             $singleOpen = $pos === call_user_func(self::$strrpos, $native, '(');
         }
         $pos++;
     }
     $center = $this->point->parseInput($native, $pos);
     if (')' === $this->nextChar($native, $pos) && $singleOpen) {
         $hasDelimiters = false;
         $pos++;
     }
     $this->expectChar($native, $pos, ',');
     $len = strcspn($native, ',)>', $pos);
     $radius = call_user_func(self::$substr, $native, $pos, $len);
     $pos += $len;
     if ($hasDelimiters) {
         $this->expectChar($native, $pos, $angleDelimiter ? '>' : ')');
     }
     return new Circle($center, $this->_float->input($radius));
 }
开发者ID:sad-spirit,项目名称:pg-wrapper,代码行数:26,代码来源:CircleConverter.php

示例11: createSitepageMaster

/**
 * Create a new Page Template
 * @param string Name
 * @param string Description
 * @param string Filename of the template
 * @param string Template
 * @param integer GUID of Cluster Template
 * @param integer Id of Type (1=singlepage, 2=multipage)
 * @param integer OPtional key to use.
 */
function createSitepageMaster($name, $description, $templatePath, $template, $clt, $type, $id = null)
{
    global $db, $c, $errors;
    if ($id == null) {
        $id = nextGUID();
    }
    $name = makeCopyName("sitepage_master", "NAME", parseSQL($name), "VERSION=0 AND DELETED=0");
    $description = parseSQL($description);
    $filename = substr($templatePath, 0, strcspn($templatePath, "."));
    $filesuffix = $templatePath = substr($templatePath, strcspn($templatePath, ".") + 1);
    $templatePath = makeUniqueFilename($c["devpath"], parseSQL($filename), $filesuffix);
    $fp = @fopen($c["devpath"] . $templatePath, "w+");
    if ($fp != "") {
        @fwrite($fp, $template);
        @fclose($fp);
    } else {
        $errors .= "--Could not write spm: " . $templatePath;
    }
    $sql = "INSERT INTO sitepage_master (SPM_ID, NAME, DESCRIPTION, TEMPLATE_PATH, CLT_ID, SPMTYPE_ID) VALUES ";
    $sql .= "({$id}, '{$name}', '{$description}', '{$templatePath}', {$clt}, {$type})";
    $query = new query($db, $sql);
    $query->free();
    $variations = createDBCArray("variations", "VARIATION_ID", "1");
    for ($i = 0; $i < count($variations); $i++) {
        $sql = "INSERT INTO sitepage_variations (SPM_ID, VARIATION_ID) VALUES ( {$id}, " . $variations[$i] . ")";
        $query = new query($db, $sql);
        $query->free();
    }
    return $id;
}
开发者ID:BackupTheBerlios,项目名称:nxwcms-svn,代码行数:40,代码来源:sitepage_master.php

示例12: stringToBin

 public function stringToBin($str)
 {
     $alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,-";
     $nbits = 6;
     $length = strlen($str);
     $out = '';
     $at = 0;
     $rshift = 0;
     $char_in = 0;
     $char_out = chr(0);
     while (1) {
         $char_in = strcspn($alpha, $str[$at++]);
         if ($rshift > 0) {
             $char_out |= chr($char_in << 8 - $rshift);
             $out .= $char_out;
             $char_out = chr(0);
             if ($at >= $length) {
                 break;
             }
         }
         $char_out |= chr($char_in >> $rshift);
         $rshift += 2;
         if ($rshift === 8) {
             $rshift = 0;
         }
     }
     return $out;
 }
开发者ID:elementgreen,项目名称:affiliates-manager-plugin,代码行数:28,代码来源:BinConverter.php

示例13: format

 /**
  * Format a string containing `<styles>`...`</>` sequences
  *
  * @param  string $in
  * @param  string[] $stack
  * @return string
  */
 public static function format($in, &$stack)
 {
     $offset = 0;
     $length = strlen($in);
     $formatted = '';
     do {
         $p = strcspn($in, '<', $offset);
         $formatted .= substr($in, $offset, $p);
         $offset += $p + 1;
         if ($offset >= $length) {
             break;
         }
         $e = strcspn($in, '>', $offset);
         $token = substr($in, $offset, $e);
         if ('' === $token) {
             $e = strpos($in, '</>', $offset) - $offset;
             $formatted .= substr($in, $offset + 1, $e - 1);
             $e += 2;
         } else {
             if ('/' === $token[0]) {
                 $formatted .= array_pop($stack);
             } else {
                 if (strlen($token) !== strspn($token, 'abcdefghijklmnopqrstuvwxyz0123456789-,@')) {
                     $formatted .= substr($in, $offset - 1, $e + 1 + 1);
                 } else {
                     list($set, $unset) = Terminal::transition($token);
                     $formatted .= $set;
                     $stack[] = $unset;
                 }
             }
         }
         $offset += $e + 1;
     } while ($offset < $length);
     return $formatted;
 }
开发者ID:xp-forge,项目名称:terminal,代码行数:42,代码来源:Terminal.class.php

示例14: sql_compile_placeholder

function sql_compile_placeholder($tmpl)
{
    $compiled = array();
    $p = 0;
    $i = 0;
    $has_named = false;
    while (false !== ($start = $p = strpos($tmpl, "?", $p))) {
        switch ($c = substr($tmpl, ++$p, 1)) {
            case "%":
            case "@":
            case "#":
                $type = $c;
                ++$p;
                break;
            default:
                $type = "";
        }
        $len = strcspn(substr($tmpl, $p), " \t\r\n,;()[]/");
        if ($len) {
            $key = substr($tmpl, $p, $len);
            $has_named = true;
            $p += $len;
        } else {
            $key = $i++;
        }
        $compiled[] = array($key, $type, $start, $p - $start);
    }
    return array($compiled, $tmpl, $has_named);
}
开发者ID:gionniboy,项目名称:0x88,代码行数:29,代码来源:lib.placeholder.php

示例15: pair

 /**
  * Writes a pair
  *
  * @param  string $name
  * @param  [:string] $attributes
  * @param  var $value
  * @return void
  */
 public function pair($name, $attributes, $value)
 {
     if (is_array($value)) {
         foreach ($value as $element) {
             $this->pair($name, $attributes, $element);
         }
     } else {
         if ($value instanceof Object) {
             $value->write($this, $name);
         } else {
             if (null !== $value) {
                 $key = strtoupper($name);
                 foreach ($attributes as $name => $attribute) {
                     if (null === $attribute) {
                         continue;
                     } else {
                         if (strcspn($attribute, '=;:') < strlen($attribute)) {
                             $pair = strtoupper($name) . '="' . $attribute . '"';
                         } else {
                             $pair = strtoupper($name) . '=' . $attribute;
                         }
                     }
                     if (strlen($key) + strlen($pair) > self::WRAP) {
                         $this->writer->writeLine($key . ';');
                         $key = ' ' . $pair;
                     } else {
                         $key .= ';' . $pair;
                     }
                 }
                 $this->writer->writeLine(wordwrap($key . ':' . strtr($value, ["\n" => '\\n']), self::WRAP, "\r\n ", true));
             }
         }
     }
 }
开发者ID:xp-forge,项目名称:ical,代码行数:42,代码来源:Output.class.php


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