本文整理汇总了PHP中strspn函数的典型用法代码示例。如果您正苦于以下问题:PHP strspn函数的具体用法?PHP strspn怎么用?PHP strspn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strspn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hex2bin
/**
* Implementation of hex2bin (which is missing For PHP version < 5.4.0)
*
* @codeCoverageIgnore
*
* @param string $sData
*
* @return string
*/
function hex2bin($sData)
{
static $mOld;
if ($mOld === null) {
$mOld = version_compare(PHP_VERSION, '5.2', '<');
}
$blIsObject = false;
if (is_scalar($sData) || ($blIsObject = is_object($sData)) && method_exists($sData, '__toString')) {
if ($blIsObject && $mOld) {
ob_start();
echo $sData;
$sData = ob_get_clean();
} else {
$sData = (string) $sData;
}
} else {
trigger_error(__FUNCTION__ . '() expects parameter 1 to be string, ' . gettype($sData) . ' given', E_USER_WARNING);
return null;
//null in this case
}
$iLength = strlen($sData);
if ($iLength % 2) {
trigger_error(__FUNCTION__ . '(): Hexadecimal input string must have an even length', E_USER_WARNING);
return false;
}
if (strspn($sData, '0123456789abcdefABCDEF') != $iLength) {
trigger_error(__FUNCTION__ . '(): Input string must be hexadecimal string', E_USER_WARNING);
return false;
}
return pack('H*', $sData);
}
示例2: checkLength
/**
* Check the number of digits.
* Pass the number as string, if starting letter is beginning zero.
*
* @param integer|string $number
* @param integer $digit
* @return bool
*/
public static function checkLength($number, $digit)
{
if (strlen($number) !== $digit || strspn($number, '1234567890') !== $digit) {
return false;
}
return true;
}
示例3: smarty_modifier_domain
/**
*
*
* @file modifier.domain.php
* @package plugins
* @author liyudong@baidu.com
* @date 2011-11-03 10:47
*/
function smarty_modifier_domain($string, $encodeURI = false)
{
$logArr['smarty_modifier'] = "modifier_domain";
$status = 0;
$logArr['url'] = $string;
$domain = $string;
if (strncasecmp($domain, "http://", 7) == 0) {
$domain = substr($domain, 7);
} elseif (strncasecmp($domain, "url:", 4) == 0) {
$pos = strspn($domain, " ", 4);
$domain = substr($domain, 4 + $pos);
if (strncasecmp($domain, "http://", 7) == 0) {
$domain = substr($domain, 7);
}
}
if (strlen($domain) == 0) {
$domain = $string;
}
if ($encodeURI) {
$result = hilight_encodeURI($domain);
$logArr['result'] = $result;
if (false === $result) {
$status = -1;
CLog::warning("fail to call hilight_domain", $status, $logArr, 1);
return $domain;
}
} else {
$result = $domain;
}
return $result;
}
示例4: __construct
/**
* Creates a new pattern layout
*
* @param string format
*/
public function __construct($format)
{
for ($i = 0, $s = strlen($format); $i < $s; $i++) {
if ('%' === $format[$i]) {
if (++$i >= $s) {
throw new \lang\IllegalArgumentException('Not enough input at position ' . ($i - 1));
}
switch ($format[$i]) {
case '%':
// Literal percent
$this->format[] = '%';
break;
case 'n':
$this->format[] = "\n";
break;
default:
// Any other character - verify it's supported
if (!strspn($format[$i], 'mclLtpx')) {
throw new \lang\IllegalArgumentException('Unknown format token "' . $format[$i] . '"');
}
$this->format[] = '%' . $format[$i];
}
} else {
$this->format[] = $format[$i];
}
}
}
示例5: tableName
public function tableName($name)
{
if (strspn($name, "1234567890qwertyuiopasdfghjklzxcvbnm_") != strlen($name)) {
new Error_Critic('', 'Invalid table name format.');
}
return '"' . $name . '"';
}
示例6: guess
/**
* @param string|array $words
* @param string $word
*
* @return string|false
*/
public function guess($words, $word)
{
if (is_string($words)) {
$words = strpos($words, ',') !== false ? explode(',', $words) : [$words];
}
$word = strtolower($word);
/** @noinspection ForeachSourceInspection */
foreach ($words as $v) {
if (strtolower($v) === $word) {
return $v;
}
}
/** @noinspection ForeachSourceInspection */
foreach ($words as $k => $v) {
if (strspn($word, strtolower($v)) !== strlen($word)) {
unset($words[$k]);
}
}
if (count($words) === 0) {
return false;
} elseif (count($words) === 1) {
return array_values($words)[0];
} else {
return false;
}
}
示例7: save
public function save()
{
$isnew = null === $this->id;
if (empty($this->title)) {
$this->title = $this->name;
}
if (empty($this->name)) {
throw new ValidationException('name', t('Внутреннее имя типа ' . 'не может быть пустым.'));
} elseif (strspn(strtolower($this->name), 'abcdefghijklmnopqrstuvwxyz0123456789_') != strlen($this->name)) {
throw new ValidationException('name', t('Внутреннее имя типа может ' . 'содержать только латинские буквы, арабские цифры и прочерк.'));
}
parent::checkUnique('name', t('Тип документа со внутренним именем %name уже есть.', array('%name' => $this->name)));
// Подгружаем поля, ранее описанные отдельными объектами (9.03 => 9.05).
$this->backportLinkedFields();
// Добавляем привычные поля, если ничего нет.
if ($isnew and empty($this->fields)) {
$this->fields = array('name' => array('type' => 'TextLineControl', 'label' => t('Название'), 'required' => true, 'weight' => 10), 'uid' => array('type' => 'UserControl', 'label' => t('Автор'), 'required' => true, 'weight' => 20), 'created' => array('type' => class_exists('DateTimeControl') ? 'DateTimeControl' : 'TextLineControl', 'label' => t('Дата создания'), 'weight' => 100));
}
// Всегда сохраняем без очистки.
parent::save();
$this->publish();
// Обновляем тип документов, если он изменился.
if (null !== $this->oldname and $this->name != $this->oldname) {
$this->getDB()->exec("UPDATE `node` SET `class` = ? WHERE `class` = ?", array($this->name, $this->oldname));
}
// Обновляем кэш.
$this->flush();
return $this;
}
示例8: header
function header($match, $state, $pos)
{
global $conf;
// get level and title
$title = trim($match);
$level = 7 - strspn($title, '=');
if ($level < 1) {
$level = 1;
}
$title = trim($title, '=');
$title = trim($title);
if ($this->status['section']) {
$this->_addCall('section_close', array(), $pos);
}
if ($level <= $conf['maxseclevel']) {
$this->_addCall('section_edit', array($this->status['section_edit_start'], $pos - 1, $this->status['section_edit_level'], $this->status['section_edit_title']), $pos);
$this->status['section_edit_start'] = $pos;
$this->status['section_edit_level'] = $level;
$this->status['section_edit_title'] = $title;
}
$this->_addCall('header', array($title, $level, $pos), $pos);
$this->_addCall('section_open', array($level), $pos);
$this->status['section'] = TRUE;
return TRUE;
}
示例9: handle
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler){
global $conf;
switch ($state) {
case DOKU_LEXER_ENTER:
case DOKU_LEXER_SPECIAL:
$data = strtolower(trim(substr($match,strpos($match,' '),-1)," \t\n/"));
return array($state, $data);
case DOKU_LEXER_UNMATCHED:
$handler->_addCall('cdata', array($match), $pos);
break;
case DOKU_LEXER_MATCHED:
// we have a == header ==, use the core header() renderer
// (copied from core header() in inc/parser/handler.php)
$title = trim($match);
$level = 7 - strspn($title,'=');
if($level < 1) $level = 1;
$title = trim($title,'=');
$title = trim($title);
$handler->_addCall('header',array($title,$level,$pos), $pos);
// close the section edit the header could open
if ($title && $level <= $conf['maxseclevel']) {
$handler->addPluginCall('wrap_closesection', array(), DOKU_LEXER_SPECIAL, $pos, '');
}
break;
case DOKU_LEXER_EXIT:
return array($state, '');
}
return false;
}
示例10: normalize
/**
* Normalize address
*
* @param string addr
* @return string
*/
public static function normalize($addr)
{
$out = '';
$hexquads = explode(':', $addr);
// Shortest address is ::1, this results in 3 parts...
if (sizeof($hexquads) < 3) {
throw new \lang\FormatException('Address contains less than 1 hexquad part: [' . $addr . ']');
}
if ('' == $hexquads[0]) {
array_shift($hexquads);
}
foreach ($hexquads as $hq) {
if ('' == $hq) {
$out .= str_repeat('0000', 8 - (sizeof($hexquads) - 1));
continue;
}
// Catch cases like ::ffaadd00::
if (strlen($hq) > 4) {
throw new \lang\FormatException('Detected hexquad w/ more than 4 digits in [' . $addr . ']');
}
// Not hex
if (strspn($hq, '0123456789abcdefABCDEF') < strlen($hq)) {
throw new \lang\FormatException('Illegal digits in [' . $addr . ']');
}
$out .= str_repeat('0', 4 - strlen($hq)) . $hq;
}
return $out;
}
示例11: 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;
}
示例12: handle
function handle($match, $state, $pos, Doku_Handler $handler)
{
global $conf;
// get level and title
$title = trim($match);
if ($this->getConf('precedence') == 'dokuwiki' && $title[strlen($title) - 1] == '=') {
// DokuWiki
$level = 7 - strspn($title, '=');
} else {
// Creole
$level = strspn($title, '=');
}
if ($level < 1) {
$level = 1;
} elseif ($level > 5) {
$level = 5;
}
$title = trim($title, '=');
$title = trim($title);
if ($handler->status['section']) {
$handler->_addCall('section_close', array(), $pos);
}
$handler->_addCall('header', array($title, $level, $pos), $pos);
$handler->_addCall('section_open', array($level), $pos);
$handler->status['section'] = true;
return true;
}
示例13: handle
function handle($match, $state, $pos, &$handler)
{
global $conf;
$title = trim($match);
$level = strspn($title, '#');
$title = trim($title, '#');
$title = trim($title);
if ($level < 1) {
$level = 1;
} elseif ($level > 6) {
$level = 6;
}
if ($handler->status['section']) {
$handler->_addCall('section_close', array(), $pos);
}
if ($level <= $conf['maxseclevel']) {
$handler->status['section_edit_start'] = $pos;
$handler->status['section_edit_level'] = $level;
$handler->status['section_edit_title'] = $title;
}
$handler->_addCall('header', array($title, $level, $pos), $pos);
$handler->_addCall('section_open', array($level), $pos);
$handler->status['section'] = true;
return true;
}
示例14: whileValid
public static function whileValid($valueToSanitize, $useMethod, $extraChars = "")
{
// Prepare Values
$sanitized = self::$useMethod($valueToSanitize, $extraChars);
$pos = strspn($valueToSanitize ^ $sanitized, "");
return substr($valueToSanitize, 0, $pos);
}
示例15: isAbsolutePath
/**
* @param $file
*
* @return bool
*/
private function isAbsolutePath($file)
{
if (strspn($file, '/\\', 0, 1) || strlen($file) > 3 && ctype_alpha($file[0]) && substr($file, 1, 1) === ':' && strspn($file, '/\\', 2, 1) || null !== parse_url($file, PHP_URL_SCHEME)) {
return true;
}
return false;
}