本文整理汇总了PHP中strspn函数的典型用法代码示例。如果您正苦于以下问题:PHP strspn函数的具体用法?PHP strspn怎么用?PHP strspn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strspn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:ioanok,项目名称:symfoxid,代码行数:40,代码来源:oxpspaymorrowclient.php
示例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;
}
开发者ID:serima,项目名称:mynumber,代码行数:15,代码来源:MyNumber.php
示例3: smarty_modifier_domain
/**
*
*
* @file modifier.domain.php
* @package plugins
* @author [email protected]
* @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;
}
开发者ID:drehere,项目名称:shenmegui,代码行数:39,代码来源:modifier.domain.php
示例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];
}
}
}
开发者ID:johannes85,项目名称:core,代码行数:32,代码来源:PatternLayout.class.php
示例5: tableName
public function tableName($name)
{
if (strspn($name, "1234567890qwertyuiopasdfghjklzxcvbnm_") != strlen($name)) {
new Error_Critic('', 'Invalid table name format.');
}
return '"' . $name . '"';
}
开发者ID:aottibia,项目名称:www,代码行数:7,代码来源:database_pgsql.php
示例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;
}
}
开发者ID:manaphp,项目名称:manaphp,代码行数:32,代码来源:Crossword.php
示例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;
}
开发者ID:umonkey,项目名称:molinos-cms,代码行数:29,代码来源:node.type.php
示例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;
}
开发者ID:krayon,项目名称:flyspray,代码行数:25,代码来源:handler.php
示例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;
}
开发者ID:rusidea,项目名称:analitika,代码行数:36,代码来源:div.php
示例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;
}
开发者ID:johannes85,项目名称:core,代码行数:34,代码来源:Inet6Address.class.php
示例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;
}
开发者ID:xp-forge,项目名称:mirrors,代码行数:29,代码来源:TagsSource.class.php
示例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;
}
开发者ID:araname,项目名称:plugin-creole,代码行数:27,代码来源:header.php
示例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;
}
开发者ID:alecordev,项目名称:dokuwiki-compendium,代码行数:25,代码来源:headeratx.php
示例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);
}
开发者ID:SkysteedDevelopment,项目名称:Deity,代码行数:7,代码来源:Sanitize.php
示例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;
}
开发者ID:PierreCharles,项目名称:uFramework-PHP,代码行数:12,代码来源:TemplateEngine.php
示例16: __construct
function __construct($parser, $line)
{
$this->level = strspn($line, ' ');
parent::__construct('ul', 'li', $this->level);
$line = substr($line, $this->level + 1);
$this->last = $this->last->insert($parser->lineFactory($line));
}
开发者ID:kurari,项目名称:Nyaa-System,代码行数:7,代码来源:list.class.php
示例17: parse
/**
* {@inheritdoc}
*/
public function parse($node)
{
$content = html_entity_decode($node->ownerDocument->saveHtml($node));
$content = str_replace(['<code>', '</code>'], null, $content);
$lines = preg_split('/\\r\\n|\\r|\\n/', $content);
$total = count($lines);
if ($total > 1) {
$first = trim($lines[0]);
$last = trim($lines[$total - 1]);
$first = trim($first, "
");
$last = trim($last, "
");
if (empty($first)) {
array_shift($lines);
}
if (empty($last)) {
array_pop($lines);
}
$markdown = '~~~' . PHP_EOL;
$i = 0;
foreach ($lines as $line) {
if ($i === 0) {
$spaces = strspn($line, ' ');
}
$markdown .= substr($line, $spaces) . PHP_EOL;
$i++;
}
$markdown .= '~~~';
return PHP_EOL . PHP_EOL . $markdown . PHP_EOL . PHP_EOL;
}
return '`' . $lines[0] . '`';
}
开发者ID:progmedia,项目名称:markdownable,代码行数:34,代码来源:Code.php
示例18: __construct
/**
* Constructor. Accepts one of the following:
*
* <ul>
* <li>The values TRUE or FALSE</li>
* <li>An integer - any non-zero value will be regarded TRUE</li>
* <li>The strings "true" and "false", case-insensitive</li>
* <li>Numeric strings - any non-zero value will be regarded TRUE</li>
* </ul>
*
* @param var value
* @throws lang.IllegalArgumentException if value is not acceptable
*/
public function __construct($value)
{
if (TRUE === $value || FALSE === $value) {
$this->value = $value;
} else {
if (is_int($value)) {
$this->value = 0 !== $value;
} else {
if ('0' === $value) {
$this->value = FALSE;
} else {
if (is_string($value) && ($l = strlen($value)) && strspn($value, '1234567890') === $l) {
$this->value = TRUE;
} else {
if (0 === strncasecmp($value, 'true', 4)) {
$this->value = TRUE;
} else {
if (0 === strncasecmp($value, 'false', 5)) {
$this->value = FALSE;
} else {
throw new IllegalArgumentException('Not a valid boolean: ' . xp::stringOf($value));
}
}
}
}
}
}
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:41,代码来源:Boolean.class.php
示例19: connect
/**
* Connect to the specified port. If called when the socket is
* already connected, it disconnects and connects again.
*
* @param $addr string IP address or host name
* @param $port int TCP port number
* @param $persistent bool (optional) whether the connection is
* persistent (kept open between requests by the web server)
* @param $timeout int (optional) how long to wait for data
* @access public
* @return mixed true on success or error object
*/
function connect($addr, $port, $persistent = null, $timeout = null)
{
if (is_resource($this->fp)) {
@fclose($this->fp);
$this->fp = null;
}
if (strspn($addr, '.0123456789') == strlen($addr)) {
$this->addr = $addr;
} else {
$this->addr = gethostbyname($addr);
}
$this->port = $port % 65536;
if ($persistent !== null) {
$this->persistent = $persistent;
}
if ($timeout !== null) {
$this->timeout = $timeout;
}
$openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
$errno = 0;
$errstr = '';
if ($this->timeout) {
$fp = $openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
} else {
$fp = $openfunc($this->addr, $this->port, $errno, $errstr);
}
if (!$fp) {
return $this->raiseError($errstr, $errno);
}
$this->fp = $fp;
return $this->setBlocking($this->blocking);
}
开发者ID:mickdane,项目名称:zidisha,代码行数:44,代码来源:Socket.php
示例20: handle
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler)
{
global $conf;
switch ($state) {
case DOKU_LEXER_ENTER:
$data = strtolower(trim(substr($match, strpos($match, ' '), -1)));
return array($state, $data);
case DOKU_LEXER_UNMATCHED:
// check if $match is a == header ==
$headerMatch = preg_grep('/([ \\t]*={2,}[^\\n]+={2,}[ \\t]*(?=))/msSi', array($match));
if (empty($headerMatch)) {
$handler->_addCall('cdata', array($match), $pos);
} else {
// if it's 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, '');
}
}
return false;
case DOKU_LEXER_EXIT:
return array($state, '');
}
return false;
}
开发者ID:JakubKrizka,项目名称:homepage-02,代码行数:37,代码来源:div.php
注:本文中的strspn函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论