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


PHP substr_compare函数代码示例

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


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

示例1: entry

function entry(&$argv)
{
    if (is_file($argv[0])) {
        if (0 === substr_compare($argv[0], '.class.php', -10)) {
            $uri = realpath($argv[0]);
            if (null === ($cl = \lang\ClassLoader::getDefault()->findUri($uri))) {
                throw new \Exception('Cannot load ' . $uri . ' - not in class path');
            }
            return $cl->loadUri($uri)->literal();
        } else {
            if (0 === substr_compare($argv[0], '.xar', -4)) {
                $cl = \lang\ClassLoader::registerPath($argv[0]);
                if (!$cl->providesResource('META-INF/manifest.ini')) {
                    throw new \Exception($cl->toString() . ' does not provide a manifest');
                }
                $manifest = parse_ini_string($cl->getResource('META-INF/manifest.ini'));
                return strtr($manifest['main-class'], '.', '\\');
            } else {
                array_unshift($argv, 'eval');
                return 'xp\\runtime\\Evaluate';
            }
        }
    } else {
        return strtr($argv[0], '.', '\\');
    }
}
开发者ID:xp-runners,项目名称:main,代码行数:26,代码来源:entry.php

示例2: __autoload

/**
 * phplogmon
 *
 * Copyright (c) 2012-2014 Holger de Carne and contributors, All Rights Reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
function __autoload($name)
{
    if (substr_compare($name, "GeoIp2\\", 0, strlen("GeoIp2\\")) == 0) {
        $includeFile = dirname(__FILE__);
        $includeFile .= DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "ext-lib" . DIRECTORY_SEPARATOR;
        if ("\\" != DIRECTORY_SEPARATOR) {
            $includeFile .= str_replace("\\", DIRECTORY_SEPARATOR, $name);
        } else {
            $includeFile .= $name;
        }
        $includeFile .= ".php";
    } elseif (substr_compare($name, "MaxMind\\", 0, strlen("MaxMind\\")) == 0) {
        $includeFile = dirname(__FILE__);
        $includeFile .= DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "ext-lib" . DIRECTORY_SEPARATOR;
        if ("\\" != DIRECTORY_SEPARATOR) {
            $includeFile .= str_replace("\\", DIRECTORY_SEPARATOR, $name);
        } else {
            $includeFile .= $name;
        }
        $includeFile .= ".php";
    } else {
        $includeFile = $name;
        $includeFile .= ".class.php";
    }
    include $includeFile;
}
开发者ID:TheBillPleaseZA,项目名称:phplogmon,代码行数:44,代码来源:autoload.php

示例3: compile

 /**
  * Compiles code for the execution of block plugin
  * 
  * @param array $args array with attributes from parser
  * @param string $tag name of block function
  * @param string $methode name of methode to call
  * @param object $compiler compiler object
  * @return string compiled code
  */
 public function compile($args, $compiler, $tag, $methode)
 {
     $this->compiler = $compiler;
     if (strlen($tag) < 5 || substr_compare($tag, 'close', -5, 5) != 0) {
         // opening tag of block plugin
         $this->required_attributes = array();
         $this->optional_attributes = array('_any');
         // check and get attributes
         $_attr = $this->_get_attributes($args);
         // convert attributes into parameter array string
         $_paramsArray = array();
         foreach ($_attr as $_key => $_value) {
             if (is_int($_key)) {
                 $_paramsArray[] = "{$_key}=>{$_value}";
             } else {
                 $_paramsArray[] = "'{$_key}'=>{$_value}";
             }
         }
         $_params = 'array(' . implode(",", $_paramsArray) . ')';
         $this->_open_tag($tag . '->' . $methode, $_params);
         // compile code
         $output = '<?php $_block_repeat=true; $_smarty_tpl->smarty->registered_objects[\'' . $tag . '\'][0]->' . $methode . '(' . $_params . ', null, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl);while ($_block_repeat) { ob_start();?>';
     } else {
         // closing tag of block plugin
         $_params = $this->_close_tag(substr($tag, 0, -5) . '->' . $methode);
         // This tag does create output
         $this->compiler->has_output = true;
         // compile code
         $output = '<?php $_block_content = ob_get_contents(); ob_end_clean(); $_block_repeat=false; echo $_smarty_tpl->smarty->registered_objects[\'' . substr($tag, 0, -5) . '\'][0]->' . $methode . '(' . $_params . ', $_block_content, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl); }?>';
     }
     return $output;
 }
开发者ID:purna89,项目名称:TrellisDesk,代码行数:41,代码来源:smarty_internal_compile_private_object_block_function.php

示例4: extract

 public function extract($pathExtracted)
 {
     if (substr_compare($pathExtracted, '/', -1)) {
         $pathExtracted .= '/';
     }
     $fileselector = array();
     $list = array();
     $count = $this->ziparchive->numFiles;
     if ($count === 0) {
         return 0;
     }
     for ($i = 0; $i < $count; $i++) {
         $entry = $this->ziparchive->statIndex($i);
         $filename = str_replace('\\', '/', $entry['name']);
         $parts = explode('/', $filename);
         if (!strncmp($filename, '/', 1) || array_search('..', $parts) !== false || strpos($filename, ':') !== false) {
             return 0;
         }
         $fileselector[] = $entry['name'];
         $list[] = array('filename' => $pathExtracted . $entry['name'], 'stored_filename' => $entry['name'], 'size' => $entry['size'], 'compressed_size' => $entry['comp_size'], 'mtime' => $entry['mtime'], 'index' => $i, 'crc' => $entry['crc']);
     }
     $res = $this->ziparchive->extractTo($pathExtracted, $fileselector);
     if ($res === false) {
         return 0;
     }
     return $list;
 }
开发者ID:0h546f6f78696342756e4e59,项目名称:piwik,代码行数:27,代码来源:ZipArchive.php

示例5: stripUtf8Bom

 /**
  * This method originates from Dropbox,
  * @link http://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/source-class-Dropbox.Util.html#14-32
  *
  * If the given string begins with the UTF-8 BOM (byte order mark), remove it and
  * return whatever is left. Otherwise, return the original string untouched.
  *
  * Though it's not recommended for UTF-8 to have a BOM, the standard allows it to
  * support software that isn't Unicode-aware.
  *
  * @param string $string
  *    A UTF-8 encoded string.
  *
  * @return string
  */
 public static function stripUtf8Bom($string)
 {
     if (\substr_compare($string, "", 0, 3) === 0) {
         $string = \substr($string, 3);
     }
     return $string;
 }
开发者ID:jaroslavtyc,项目名称:granam-string,代码行数:22,代码来源:StringTools.php

示例6: handleError

 /**
  * {@inheritdoc}
  */
 public function handleError(array $error, FatalErrorException $exception)
 {
     $messageLen = strlen($error['message']);
     $notFoundSuffix = '\' not found';
     $notFoundSuffixLen = strlen($notFoundSuffix);
     if ($notFoundSuffixLen > $messageLen) {
         return;
     }
     if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) {
         return;
     }
     foreach (array('class', 'interface', 'trait') as $typeName) {
         $prefix = ucfirst($typeName) . ' \'';
         $prefixLen = strlen($prefix);
         if (0 !== strpos($error['message'], $prefix)) {
             continue;
         }
         $fullyQualifiedClassName = substr($error['message'], $prefixLen, -$notFoundSuffixLen);
         if (false !== ($namespaceSeparatorIndex = strrpos($fullyQualifiedClassName, '\\'))) {
             $className = substr($fullyQualifiedClassName, $namespaceSeparatorIndex + 1);
             $namespacePrefix = substr($fullyQualifiedClassName, 0, $namespaceSeparatorIndex);
             $message = sprintf('Attempted to load %s "%s" from namespace "%s" in %s line %d. Do you need to "use" it from another namespace?', $typeName, $className, $namespacePrefix, $error['file'], $error['line']);
         } else {
             $className = $fullyQualifiedClassName;
             $message = sprintf('Attempted to load %s "%s" from the global namespace in %s line %d. Did you forget a use statement for this %s?', $typeName, $className, $error['file'], $error['line'], $typeName);
         }
         if ($classes = $this->getClassCandidates($className)) {
             $message .= sprintf(' Perhaps you need to add a use statement for one of the following: %s.', implode(', ', $classes));
         }
         return new ClassNotFoundException($message, $exception);
     }
 }
开发者ID:roberto-sanchez,项目名称:gardencentral,代码行数:35,代码来源:ClassNotFoundFatalErrorHandler.php

示例7: testConvert

 /**
  * @param string $inputFile
  * @param string $outputFile
  *
  * @dataProvider providerForTestConvert
  */
 public function testConvert($inputFile, $outputFile)
 {
     $endsWith = ".lossy.xml";
     if (substr_compare($inputFile, $endsWith, -strlen($endsWith), strlen($endsWith)) === 0) {
         $this->markTestSkipped("Skipped lossy conversion.");
     }
     if (!file_exists($outputFile)) {
         $this->markTestIncomplete("Test is not complete: missing output fixture: " . $outputFile);
     }
     $inputDocument = $this->createDocument($inputFile);
     $outputDocument = $this->createDocument($outputFile);
     $this->removeComments($inputDocument);
     $this->removeComments($outputDocument);
     $converter = $this->getConverter();
     $convertedDocument = $converter->convert($inputDocument);
     // Needed by some disabled output escaping (eg. legacy ezxml paragraph <line/> elements)
     $convertedDocumentNormalized = new DOMDocument();
     $convertedDocumentNormalized->loadXML($convertedDocument->saveXML());
     $this->assertEquals($outputDocument, $convertedDocumentNormalized);
     $validator = $this->getConversionValidator();
     if (isset($validator)) {
         $errors = $validator->validate($convertedDocument);
         $this->assertTrue(empty($errors), "Conversion result did not validate against the configured schemas:" . $this->formatValidationErrors($outputFile, $errors));
     }
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:31,代码来源:BaseTest.php

示例8: setType

 /**
  * Set the Internet media type. Allow only video types + Flash wrapper.
  *
  * @param string $type Internet media type
  */
 public function setType($type)
 {
     if ($type === 'application/x-shockwave-flash' || substr_compare($type, 'video/', 0, 6) === 0) {
         $this->type = $type;
     }
     return $this;
 }
开发者ID:chewbakka,项目名称:open-graph-protocol-tools,代码行数:12,代码来源:OpenGraphProtocolVideo.php

示例9: fixPath

 /**
  * Make sure target path ends in '/'
  *
  * @param string $path
  *
  * @return string
  */
 private function fixPath($path)
 {
     if (substr_compare($path, '/', -1)) {
         $path .= '/';
     }
     return $path;
 }
开发者ID:besimhu,项目名称:CraftCMS-Boilerplate,代码行数:14,代码来源:Unzip.php

示例10: endsWith

 public function endsWith($string)
 {
     $rep = Condition::stringOf($string);
     return $this->is(new Match(function ($value) use($string) {
         return '' !== $value && 0 === substr_compare($value, $string, -strlen($string));
     }, ['%s does not end with ' . $rep, '%s ends with ' . $rep]));
 }
开发者ID:xp-forge,项目名称:assert,代码行数:7,代码来源:StringAssertions.class.php

示例11: headerFunction

 /**
  * @param resource $ch
  * @param string   $header
  *
  * @return int
  * @throws Dropbox_Exception_BadResponse
  */
 public function headerFunction($ch, $header)
 {
     // The first line is the HTTP status line (Ex: "HTTP/1.1 200 OK").
     if (!$this->skippedFirstLine) {
         $this->skippedFirstLine = true;
         return strlen($header);
     }
     // If we've encountered an error on a previous callback, then there's nothing left to do.
     if ($this->error !== null) {
         return strlen($header);
     }
     // case-insensitive starts-with check.
     if (strlen($header) < 19 || substr_compare($header, "x-dropbox-metadata:", 0, 19, true) !== 0) {
         return strlen($header);
     }
     if ($this->metadata !== null) {
         $this->error = "Duplicate X-Dropbox-Metadata header";
         return strlen($header);
     }
     $headerValue = substr($header, 19);
     $parsed = json_decode($headerValue, true);
     if ($parsed === null) {
         $this->error = "Bad JSON in X-Dropbox-Metadata header";
         return strlen($header);
     }
     $this->metadata = $parsed;
     return strlen($header);
 }
开发者ID:onedaylabs,项目名称:onedaylabs.com,代码行数:35,代码来源:DropboxMetadataHeaderCatcher.php

示例12: recurse

function recurse($path)
{
    global $newpcre, $dirlen;
    foreach (scandir($path) as $file) {
        if ($file[0] === '.' || $file === 'CVS' || @substr_compare($file, '.lo', -3, 3) === 0 || @substr_compare($file, '.loT', -4, 4) === 0 || @substr_compare($file, '.o', -2, 2) === 0) {
            continue;
        }
        $file = "{$path}/{$file}";
        if (is_dir($file)) {
            recurse($file);
            continue;
        }
        echo "processing {$file}... ";
        $newfile = $newpcre . substr($file, $dirlen);
        if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) {
            $newfile = $tmp;
        }
        if (!is_file($newfile)) {
            die("{$newfile} is not available any more\n");
        }
        // maintain file mtimes so that cvs doesnt get crazy
        if (file_get_contents($newfile) !== file_get_contents($file)) {
            copy($newfile, $file);
        }
        // always include the config.h file
        $content = file_get_contents($newfile);
        $newcontent = preg_replace('/#\\s*ifdef HAVE_CONFIG_H\\s*(.+)\\s*#\\s*endif/', '$1', $content);
        if ($content !== $newcontent) {
            file_put_contents($file, $newcontent);
        }
        echo "OK\n";
    }
}
开发者ID:OTiZ,项目名称:osx,代码行数:33,代码来源:upgrade-pcre.php

示例13: print_source

/**
 * Creates a div around the javascript code to visualize it.
 * Accepts the canvas="xxx" parameter to specify the canvas name. By default it is
 * created with id='canvas' (so original uh ;-))
 */
function print_source($attr, $content)
{
    extract(shortcode_atts(array('canvas' => 'canvas'), $attr));
    $chartId = $canvas;
    $field_code = get_post_meta(get_the_ID(), $chartId, true);
    $code = "";
    $result = "";
    if (!empty($field_code)) {
        $jsonCode = json_decode($field_code, true);
        $code = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n\\']+/", "\n", $jsonCode['code']);
        // remove empty lines
        foreach ($jsonCode['includes'] as $include) {
            if (substr_compare($include, "js", -strlen("js"), strlen("js")) === 0) {
                $result = $result . getJavaScriptInclude($include);
            }
            if (substr_compare($include, "css", -strlen("css"), strlen("css")) === 0) {
                $result = $result . getCssInclude($include);
            }
        }
    } else {
        $code = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n\\']+/", "\n", $content);
        // remove empty lines
    }
    if (containsAutoIdFlag($code)) {
        $genChartId = genRandomId();
        $code = replaceAutoIdFlag($code, $genChartId);
        $chartId = $genChartId;
    }
    $code = wrapAsFunction($code, $chartId);
    $result = $result . '<div class="' . $chartId . '">' . '<script type="text/javascript">' . $code . '</script>' . '</div>';
    return $result;
}
开发者ID:qdwwqxwn,项目名称:www,代码行数:37,代码来源:wp-d3.php

示例14: next

 /** @return var */
 protected function next()
 {
     while ($this->tokens->hasMoreTokens()) {
         $token = $this->tokens->nextToken();
         if (strspn($token, ' ')) {
             continue;
         } else {
             if ('@' === $token || '$' === $token) {
                 $token .= $this->tokens->nextToken();
             } else {
                 if (0 === substr_compare($token, '...', -3)) {
                     $token = substr($token, 0, -3);
                     $this->tokens->pushBack('*');
                 }
             }
         }
         if (false !== strpos(self::DELIMITERS, $token)) {
             return $token;
         } else {
             if (isset(self::$keywords[$token])) {
                 return [self::$keywords[$token], $token];
             } else {
                 return [self::T_WORD, $token];
             }
         }
     }
     return null;
 }
开发者ID:xp-forge,项目名称:mirrors,代码行数:29,代码来源:TagsSource.class.php

示例15: warmUp

 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $finder = new \Symfony\Component\Finder\Finder();
     $finder = $finder->files()->sort(function ($a, $b) {
         $result = strcmp($a->getRealpath(), $b->getRealpath());
         return 1 == $result && 0 == substr_compare($a->getBasename(), $b->getBasename(), 0, 2) ? -1 : $result;
     });
     foreach ($this->patterns as $pattern) {
         $finder->name($pattern);
     }
     $files = $finder->in($flagsPath = $this->getAbsolutePath($this->flagsPath));
     $cache = array('flags' => array(), 'defaults' => array());
     /** @var $file \Symfony\Component\Finder\SplFileInfo */
     foreach ($files as $file) {
         $counter = 0;
         do {
             $match = preg_match($this->patterns[$counter], $file->getBasename(), $out);
         } while (!$match && $counter++ < count($this->patterns));
         $locale = $out['locale'];
         $country = isset($out['country']) ? strtolower($out['country']) : null;
         $localeString = $locale . (is_null($country) ? '' : '-' . $country);
         if ($this->isLocaleEnabled($localeString)) {
             $cache['flags'][$localeString] = new Flag($file->getRealPath(), $locale, $country);
             if (!isset($cache['defaults'][$locale])) {
                 if (isset($this->defaults[$locale])) {
                     $cache['defaults'][$locale] = strtolower($this->defaults[$locale]);
                 } else {
                     $cache['defaults'][$locale] = $localeString;
                 }
             }
         }
     }
     $this->writeCacheFile($cacheDir . DIRECTORY_SEPARATOR . 'flags.php', sprintf('<?php return unserialize(%s);' . PHP_EOL, var_export(serialize($cache), true)));
 }
开发者ID:servergrove,项目名称:servergrovelocalebundle,代码行数:37,代码来源:FlagCacheWarmer.php


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