本文整理汇总了PHP中strncmp函数的典型用法代码示例。如果您正苦于以下问题:PHP strncmp函数的具体用法?PHP strncmp怎么用?PHP strncmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strncmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: to
public static function to($url = '', $scheme = false, $urlManager = null)
{
if (is_array($url)) {
return static::toRoute($url, $scheme, $urlManager);
}
$url = Yii::getAlias($url);
if ($url === '') {
$url = Yii::$app->getRequest()->getUrl();
}
if (!$scheme) {
return $url;
}
if (strncmp($url, '//', 2) === 0) {
// e.g. //hostname/path/to/resource
return is_string($scheme) ? "{$scheme}:{$url}" : $url;
}
if (($pos = strpos($url, ':')) == false || !ctype_alpha(substr($url, 0, $pos))) {
// turn relative URL into absolute
$url = Yii::$app->getUrlManager()->getHostInfo() . '/' . ltrim($url, '/');
}
if (is_string($scheme) && ($pos = strpos($url, ':')) !== false) {
// replace the scheme with the specified one
$url = $scheme . substr($url, $pos);
}
return $url;
}
示例2: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, $content)
{
if (0 === strncmp($content, $this->BOM, 3)) {
return substr($content, 3);
}
return $content;
}
示例3: getBaseHref
protected function getBaseHref()
{
if (strncmp($this->uri, '#', 1) === 0 || strncmp($this->uri, 'mailto:', 7) === 0) {
return $this->uri;
}
return $this->controller->genUrl($this->uri);
}
示例4: display
/**
* @since 1.6
*/
function display($tpl = null)
{
// Get data from the model
$this->state = $this->get('State');
$this->changeSet = $this->get('Items');
$this->errors = $this->changeSet->check();
$this->results = $this->changeSet->getStatus();
$this->schemaVersion = $this->get('SchemaVersion');
$this->updateVersion = $this->get('UpdateVersion');
$this->filterParams = $this->get('DefaultTextFilters');
$this->schemaVersion = $this->schemaVersion ? $this->schemaVersion : JText::_('JNONE');
$this->updateVersion = $this->updateVersion ? $this->updateVersion : JText::_('JNONE');
$this->pagination = $this->get('Pagination');
$this->errorCount = count($this->errors);
$errors = count($this->errors);
if (!(strncmp($this->schemaVersion, JVERSION, 5) === 0)) {
$this->errorCount++;
}
if (!$this->filterParams) {
$this->errorCount++;
}
if ($this->updateVersion != JVERSION) {
$this->errorCount++;
}
parent::display($tpl);
}
示例5: getFileUrl
/**
* Depending on original file mime type call appropriate transcoder
*/
public function getFileUrl($mixedHandler)
{
$oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']);
if (!$oStorageOriginal) {
return false;
}
$aFile = $oStorageOriginal->getFile($mixedHandler);
if (!$aFile) {
return false;
}
$sTranscoder = '';
if (0 === strncmp($aFile['mime_type'], 'image/', 6) && !empty($this->_aObject['source_params']['image'])) {
$sTranscoder = $this->_aObject['source_params']['image'];
} elseif (0 === strncmp($aFile['mime_type'], 'video/', 6) && !empty($this->_aObject['source_params']['video_poster'])) {
$sTranscoder = $this->_aObject['source_params']['video_poster'];
// if additional video transcoders provided call it to force video conversion
if (empty($this->_aObject['source_params']['video'])) {
continue;
}
foreach ($this->_aObject['source_params']['video'] as $sVideoTranscoder) {
if (!($oTranscoder = BxDolTranscoderImage::getObjectInstance($sVideoTranscoder))) {
continue;
}
$oTranscoder->getFileUrl($mixedHandler);
}
}
if (!$sTranscoder) {
return false;
}
if (!($oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder))) {
return false;
}
return $oTranscoder->getFileUrl($mixedHandler);
}
示例6: __jax__classAutoloadFindClassFile
function __jax__classAutoloadFindClassFile($class_name, $dir)
{
$cnlen = strlen($class_name);
$anyProcessed = false;
if (($dp = @opendir($dir)) !== false) {
while (($fn = readdir($dp)) !== false) {
if ($fn == '.' || $fn == '..') {
continue;
}
$path = $dir . '/' . $fn;
if (is_dir($path)) {
if (($foundfn = __jax__classAutoloadFindClassFile($class_name, $path)) !== false) {
return $foundfn;
}
}
if (is_file($path)) {
$fnlen = strlen($fn);
if ($fnlen > $cnlen && strncmp($fn, $class_name, $cnlen) == 0 && ($cnlen + 10 == $fnlen && substr_compare($fn, '.class.php', $cnlen) == 0 || $cnlen + 14 == $fnlen && substr_compare($fn, '.interface.php', $cnlen) == 0)) {
return $path;
}
}
}
closedir($dp);
}
return false;
}
示例7: get_content_dir
function get_content_dir($dir_path)
{
if (!is_dir($dir_path)) {
throw new Exception($dir_path . ' should be a directory but isn\'t.');
}
$numEntries = 0;
$lastEntry = "";
foreach (new DirectoryIterator($dir_path) as $entry) {
if (strncmp((string) $entry, '.', 1)) {
$lastEntry = (string) $entry;
$numEntries += 1;
// echo $numEntries." \n".$lastEntry." \n\n";
}
}
// echo "Final " . $numEntries." \n".$lastEntry." \n\n";
if ($numEntries == 0) {
//empty directory, just return it
return $dir_path . '/' . (string) $lastEntry;
} elseif ($numEntries == 1) {
if (!is_dir($dir_path . '/' . (string) $lastEntry)) {
//there is no directory below the current one.
return $dir_path . '/';
} else {
//there is only entry in this directory;
//as it's a subfolder, recurse into it.
//echo "recursion ".$lastEntry." \n";
return get_content_dir($dir_path . '/' . $lastEntry);
}
} else {
// there is more than one entry in this directory. Stop.
return $dir_path . '/';
}
}
示例8: smarty_core_is_secure
function smarty_core_is_secure($params, &$smarty)
{
if (!$smarty->security || $smarty->security_settings['INCLUDE_ANY']) {
return true;
}
if ($params['resource_type'] == 'file') {
$_rp = realpath($params['resource_name']);
if (isset($params['resource_base_path'])) {
foreach ((array) $params['resource_base_path'] as $curr_dir) {
if (($_cd = realpath($curr_dir)) !== false && strncmp($_rp, $_cd, strlen($_cd)) == 0 && substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) {
return true;
}
}
}
if (!empty($smarty->secure_dir)) {
foreach ((array) $smarty->secure_dir as $curr_dir) {
if (($_cd = realpath($curr_dir)) !== false) {
if ($_cd == $_rp) {
return true;
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 && substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) {
return true;
}
}
}
}
} else {
// resource is not on local file system
return call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][2], array($params['resource_name'], &$smarty));
}
return false;
}
示例9: constructUrl
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
$params = $appRequest->getParameters();
// presenter name
$presenter = $appRequest->getPresenterName();
if (strncmp($presenter, $this->module, strlen($this->module)) === 0) {
$params[self::PRESENTER_KEY] = substr($presenter, strlen($this->module));
} else {
return NULL;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
示例10: identifyLine
/**
* @inheritDoc
*/
protected function identifyLine($lines, $current)
{
if (isset($lines[$current]) && strncmp($lines[$current], '```', 3) === 0) {
return 'fencedCode';
}
return parent::identifyLine($lines, $current);
}
示例11: constructUrl
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(Nette\Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->cachedRoutes === NULL) {
$this->warmupCache();
}
if ($this->module) {
if (strncmp($tmp = $appRequest->getPresenterName(), $this->module, strlen($this->module)) === 0) {
$appRequest = clone $appRequest;
$appRequest->setPresenterName(substr($tmp, strlen($this->module)));
} else {
return NULL;
}
}
$presenter = $appRequest->getPresenterName();
if (!isset($this->cachedRoutes[$presenter])) {
$presenter = '*';
}
foreach ($this->cachedRoutes[$presenter] as $route) {
$url = $route->constructUrl($appRequest, $refUrl);
if ($url !== NULL) {
return $url;
}
}
return NULL;
}
示例12: getAssetUrl
/**
* @inheritdoc
*/
public function getAssetUrl($bundle, $asset)
{
if (($actualAsset = $this->resolveAsset($bundle, $asset)) !== false) {
if (strncmp($actualAsset, '@web/', 5) === 0) {
$asset = substr($actualAsset, 5);
$basePath = Yii::getAlias("@webroot");
$baseUrl = Yii::getAlias("@web");
} else {
$asset = Yii::getAlias($actualAsset);
$basePath = $this->basePath;
$baseUrl = $this->baseUrl;
}
} else {
$basePath = $bundle->basePath;
$baseUrl = $bundle->baseUrl;
}
if (!Url::isRelative($asset) || strncmp($asset, '/', 1) === 0) {
return $asset;
}
if ($this->appendTimestamp) {
foreach (['', '.gz'] as $appendExtension) {
if (($timestamp = @filemtime("{$basePath}/{$asset}{$appendExtension}")) > 0) {
return "{$baseUrl}/{$asset}?v={$timestamp}";
}
}
}
return "{$baseUrl}/{$asset}";
}
示例13: _detect_uri
private function _detect_uri()
{
if (!isset($_SERVER['REQUEST_URI']) or !isset($_SERVER['SCRIPT_NAME'])) {
return '';
}
$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
} elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) {
$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
if (strncmp($uri, '?/', 2) === 0) {
$uri = substr($uri, 2);
}
$parts = preg_split('#\\?#i', $uri, 2);
$uri = $parts[0];
if (isset($parts[1])) {
$_SERVER['QUERY_STRING'] = $parts[1];
parse_str($_SERVER['QUERY_STRING'], $_GET);
} else {
$_SERVER['QUERY_STRING'] = '';
$_GET = array();
}
if ($uri == '/' || empty($uri)) {
return '/';
}
$uri = parse_url($uri, PHP_URL_PATH);
return str_replace(array('//', '../'), '/', trim($uri, '/'));
}
示例14: createRequest
public function createRequest()
{
$uri = $_SERVER['REQUEST_URI'];
$basePath = $this->configuration->getBasePath();
if ($basePath && strncmp($uri, $basePath, strlen($basePath)) !== 0) {
throw new ApiException("Invalid endpoint");
}
$uri = substr($uri, strlen($basePath) - 1);
if ($this->configuration->getPublicKey() !== trim($_SERVER['HTTP_X_API_KEY'])) {
throw new AuthorizationException("Invalid API key");
}
$hasBody = $this->hasBody();
$input = $hasBody ? file_get_contents('php://input') : '';
$signature = hash_hmac('sha256', $uri . $input, $this->configuration->getPrivateKey());
if ($signature !== trim($_SERVER['HTTP_X_API_SIGNATURE'])) {
throw new AuthorizationException("Invalid signature");
}
if ($hasBody) {
$parameters = json_decode($input, JSON_OBJECT_AS_ARRAY);
if ($parameters === NULL && $input !== '' && strcasecmp(trim($input, " \t\n\r"), 'null') !== 0) {
$error = json_last_error();
throw new ApiException('JSON parsing error: ' . $error);
}
} else {
$parameters = filter_input_array(INPUT_GET, FILTER_UNSAFE_RAW);
}
$name = ($a = strpos($uri, '?')) !== FALSE ? substr($uri, 0, $a) : $uri;
return new Request(ltrim($name, '/'), $_SERVER['REQUEST_METHOD'], $parameters);
}
示例15: getTokens
protected function getTokens($code)
{
if ($this->lfLineEndings && false !== strpos($code, "\r")) {
$code = str_replace("\r\n", "\n", $code);
$code = strtr($code, "\r", "\n");
}
if ($this->checkUtf8 && !preg_match('//u', $code)) {
$this->setError("File encoding is not valid UTF-8", E_USER_WARNING);
}
if ($this->stripUtf8Bom && 0 === strncmp($code, "", 3)) {
// substr_replace() is for mbstring overloading resistance
$code = substr_replace($code, '', 0, 3);
$this->setError("Stripping UTF-8 Byte Order Mark", E_USER_NOTICE);
}
if ('' === $code) {
return array();
}
$code = parent::getTokens($code);
// Ensure that the first token is always a T_OPEN_TAG
if (T_INLINE_HTML === $code[0][0]) {
$a = $code[0][1];
$a = "\r" === $a[0] ? isset($a[1]) && "\n" === $a[1] ? '\\r\\n' : '\\r' : ("\n" === $a[0] ? '\\n' : '');
if ($a) {
array_unshift($code, array(T_OPEN_TAG, '<?php '), array(T_ECHO, 'echo'), array(T_ENCAPSED_AND_WHITESPACE, "\"{$a}\""), array(T_CLOSE_TAG, '?>'));
} else {
array_unshift($code, array(T_OPEN_TAG, '<?php '), array(T_CLOSE_TAG, '?>'));
}
}
// Ensure that the last valid PHP code position is tagged with a T_ENDPHP
$a = array_pop($code);
$code[] = T_CLOSE_TAG === $a[0] ? ';' : $a;
T_INLINE_HTML === $a[0] && ($code[] = array(T_OPEN_TAG, '<?php '));
$code[] = array(T_ENDPHP, '');
return $code;
}