本文整理汇总了PHP中ctype_space函数的典型用法代码示例。如果您正苦于以下问题:PHP ctype_space函数的具体用法?PHP ctype_space怎么用?PHP ctype_space使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ctype_space函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encode
public function encode(string $input)
{
$output = "";
$prevc = NULL;
for ($i = 0; $i < \strlen($input); $i++) {
$c = $input[$i];
if ("" < $c) {
if ($this->errorOnNonASCII) {
throw new \Exception("Error at position {$i}: non-ASCII byte '{$c}'");
}
} else {
$c = strtolower($c);
}
$replacement = $this->letters[$c] ?? $this->digits[$c] ?? NULL;
if ($replacement !== NULL && !($c === "." && $replacement === ($this->digits[$c] ?? NULL) && !ctype_digit($prevc))) {
// Insert spaces at word boundaries
if ($prevc !== NULL && !ctype_space($prevc) && !ctype_punct($prevc) || $prevc === '.' && ctype_digit($c)) {
$output .= ' ';
}
$output .= $replacement;
} else {
$output .= $c;
}
$prevc = $c;
}
return $output;
}
示例2: split
protected function split($uInput)
{
$tParts = [[], []];
$tBuffer = "";
$tQuote = false;
for ($tPosition = 0, $tLen = strlen($uInput); $tPosition < $tLen; $tPosition++) {
if ($uInput[$tPosition] === "\"") {
$tQuote = !$tQuote;
continue;
} elseif (ctype_space($uInput[$tPosition])) {
if (strlen($tBuffer) == 0) {
continue;
}
if (!$tQuote) {
if (strncmp($tBuffer, "--", 2) === 0) {
$tParts[1][] = $tBuffer;
} else {
$tParts[0][] = $tBuffer;
}
$tBuffer = "";
continue;
}
}
$tBuffer .= $uInput[$tPosition];
}
if (strlen($tBuffer) > 0) {
if (strncmp($tBuffer, "--", 2) === 0) {
$tParts[1][] = $tBuffer;
} else {
$tParts[0][] = $tBuffer;
}
}
return $tParts;
}
示例3: getStrings
/**
* Get tokens as string[] extracted from a QTI file
* XML inside qti.xml is parsed and all text is tokenized
*
* @param \core_kernel_classes_Resource $resource
* @return array
*/
public function getStrings(\core_kernel_classes_Resource $resource)
{
try {
$ontologyFiles = $resource->getPropertyValues($this->getProperty(TAO_ITEM_CONTENT_PROPERTY));
if (empty($ontologyFiles)) {
return [];
}
} catch (\core_kernel_classes_EmptyProperty $e) {
return [];
}
$file = $this->getFileReferenceSerializer()->unserializeDirectory(reset($ontologyFiles))->getFile(Service::QTI_ITEM_FILE);
if (!$file->exists()) {
return [];
}
$content = $file->read();
if (empty($content)) {
return [];
}
$dom = new \DOMDocument();
$dom->loadXML($content);
$xpath = new \DOMXPath($dom);
$textNodes = $xpath->query('//text()');
unset($xpath);
$contentStrings = array();
foreach ($textNodes as $textNode) {
if (ctype_space($textNode->wholeText) === false) {
$contentStrings[] = trim($textNode->wholeText);
}
}
return $contentStrings;
}
示例4: summarize
/**
* Ensure that text is no longer than $maxLength. If so, truncate $subject at word boundary
* closest before $maxLength and replace with $suffix
* @param string $subject Original text to summarize
* @param int $maxLength
* @param string $suffix Text to append at end if $subject is longer than $maxLength,
* @return string Truncated text followed by $suffix if necessary
*/
public static function summarize($subject, $maxLength, $suffix = '...')
{
if (!$subject) {
return '';
}
if (strlen($subject) <= $maxLength) {
return $subject;
}
$suffixLen = strlen($suffix);
// Leave space for the suffix
$index = $maxLength - $suffixLen;
// Look for a natural break after which to append the suffix
while ($index > 0) {
if (ctype_space($subject[$index])) {
break;
}
$index -= 1;
}
// Maybe it's just one very long word
// NOTE not covering case where $maxLength <= $suffixLen
if ($index <= 0) {
return substr($subject, 0, $maxLength - $suffixLen) . $suffix;
}
return substr($subject, 0, $index) . $suffix;
}
示例5: __construct
/**
* Constructor, accepts data and determines if it is whitespace.
*
* @param $data String parsed character data.
*/
public function __construct($data, $line = null, $col = null)
{
$this->data = $data;
$this->is_whitespace = ctype_space($data);
$this->line = $line;
$this->col = $col;
}
示例6: raefftec_userlist
function raefftec_userlist()
{
$users = get_users(array('meta_key' => 'last_name', 'orderby' => 'meta_value'));
$fields = array('avatar' => '', 'user_lastname' => __('Lastname', 'raefftec-userlist'), 'user_firstname' => __('Firstname', 'raefftec-userlist'), 'address' => __('Address', 'raefftec-userlist'), 'zip' => __('ZIP', 'raefftec-userlist'), 'city' => __('City', 'raefftec-userlist'), 'user_email' => __('E-Mail', 'raefftec-userlist'));
$content = '<table id="raefftec_userlist">';
$content = $content . '<thead>';
$content = $content . '<tr>';
foreach ($fields as $key => $value) {
$content = $content . '<th class="' . $key . '">' . $value . '</th>';
}
$content = $content . '</tr>';
$content = $content . '</thead>';
$content = $content . '<tbody>';
foreach ($users as $user) {
$content = $content . '<tr>';
foreach ($fields as $key => $value) {
$content = $content . '<td class="' . $key . '" data-th="' . $value . '">';
if ($key == 'avatar') {
$content = $content . get_avatar($user->ID, 48);
} else {
$data = get_the_author_meta($key, $user->ID);
$content = $content . (ctype_space($data) || $data == '' ? ' ' : $data);
}
$content = $content . '</td>';
}
$content = $content . '</tr>';
}
$content = $content . '</tbody>';
$content = $content . '</table>';
return $content;
}
示例7: validate
public function validate($string, $config, $context)
{
$string = $this->parseCDATA($string);
if ($string === '') {
return false;
}
$parts = explode(' ', $string);
// parseCDATA replaced \r, \t and \n
$length = count($parts);
$final = '';
for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {
if (ctype_space($parts[$i])) {
continue;
}
$result = $this->single->validate($parts[$i], $config, $context);
if ($result !== false) {
$final .= $result . ' ';
$num++;
}
}
if ($final === '') {
return false;
}
return rtrim($final);
}
示例8: isOptionValid
/**
* Returns whether or not the $value of a given password option $key is valid.
*/
function isOptionValid($key, $value)
{
$is_option_valid = TRUE;
// check if letter_case function does not exist
if ($key == "letter_case" && !function_exists($value)) {
$is_option_valid = FALSE;
}
// check if min_password_length is not within range
if ($key == "min_password_length" && (!ctype_digit($value) || $value < 8 || $value > 32)) {
$is_option_valid = FALSE;
}
// check if min_words is not within range
if ($key == "min_words" && (!ctype_digit($value) || $value < 2 || $value > 9)) {
$is_option_valid = FALSE;
}
// check if num_digits is not within range
if ($key == "num_digits" && (!ctype_digit($value) || $value < 0 || $value > 3)) {
$is_option_valid = FALSE;
}
// check if num_symbols is not within range
if ($key == "num_symbols" && (!ctype_digit($value) || $value < 0 || $value > 3)) {
$is_option_valid = FALSE;
}
// check if separator is not an empty string, whitespace or punctuation
if ($key == "separator" && !($value === "" || ctype_space($value) || ctype_punct($value))) {
$is_option_valid = FALSE;
}
return $is_option_valid;
}
示例9: get_real_previous_sibling
function get_real_previous_sibling($node)
{
if ($node->previousSibling && $node->previousSibling->nodeName == '#text' && ctype_space($node->previousSibling->nodeValue)) {
return $node->previousSibling->previousSibling;
}
return $node->previousSibling;
}
示例10: getTokens
function getTokens($string)
{
$tokens = array();
$len = strlen($string);
$current = '';
for ($i = 0; $len > $i; ++$i) {
$chr = $string[$i];
$end = false;
$extra = null;
if (ctype_space($chr)) {
$end = true;
} elseif ($chr == '(' || $chr == ')') {
$extra = $chr;
$end = true;
} else {
$current .= $chr;
}
if ($end && 0 != strlen($current)) {
$tokens[] = $current;
$current = '';
}
if ($extra) {
$tokens[] = $extra;
}
}
if (strlen($current) != 0) {
$tokens[] = $current;
}
return $tokens;
}
示例11: __construct
/**
* @param string $item_as_text the Node or tree in string form, ie: (NP (DT the) (JJ lazy) (NN dog))
*/
public function __construct($item_as_text)
{
$this->children = [];
$this->is_leaf = true;
$item_as_text = trim(str_replace("\n", ' ', $item_as_text));
$l = strlen($item_as_text) - 1;
if ($item_as_text[0] != '(' || $item_as_text[$l] != ')') {
throw new \Exception("Bad node format [{$item_as_text}]");
}
$t = substr($item_as_text, 1, $l - 1) . ' ';
$last_stop = 0;
$space_prev = false;
$deep = 0;
for ($i = 0; $i < $l; $i++) {
$space = ctype_space($t[$i]) && $deep == 0;
if ($space_prev && !$space) {
$last_stop = $i;
}
if ($t[$i] == '(') {
$deep++;
} else {
if ($t[$i] == ')') {
$deep--;
} else {
if ($space && !$space_prev) {
$this->addItem(substr($t, $last_stop, $i - $last_stop));
}
}
}
$space_prev = $space;
}
$this->n = array_shift($this->children);
}
示例12: finalize
function finalize()
{
// get parent's output
parent::finalize();
$output = parent::getOutput();
$tex_output = '';
foreach ($output as $token) {
if ($this->_enumerated) {
$class = $token[0];
$content = $token[1];
} else {
$key = key($token);
$class = $key;
$content = $token[$key];
}
$iswhitespace = ctype_space($content);
if (!$iswhitespace) {
if ($class === 'special') {
$class = 'code';
}
$tex_output .= sprintf('\\textcolor{%s}{%s}', $class, $this->escape($content));
} else {
$tex_output .= $content;
}
}
$this->_output = "\\begin{alltt}\n" . $tex_output . "\\end{alltt}";
}
示例13: tokenize
function tokenize($string)
{
$tokens = array();
$open = false;
$current = '';
$length = strlen($string);
for ($i = 0; $length > $i; ++$i) {
$char = $string[$i];
if ($open) {
if ($char === self::QUOTE) {
$this->addToken($tokens, $current);
$open = false;
} else {
$current .= $char;
}
} else {
if ($char === self::QUOTE) {
$open = true;
} elseif ($char === self::OPEN || $char === self::CLOSE) {
$this->addToken($tokens, $current);
$this->addToken($tokens, $char);
} elseif (ctype_space($char)) {
$this->addToken($tokens, $current);
} else {
$current .= $char;
}
}
}
$this->addToken($tokens, $current);
return $tokens;
}
示例14: validate_not_whitespace
public function validate_not_whitespace($string, $param)
{
$errors = array();
if (ctype_space($string)) {
$errors[] = $param . ' ei tule olla pelkkää whitespacea';
}
return $errors;
}
示例15: __construct
/**
* @param array $value
*
*/
protected function __construct(array $value)
{
/** @var \AGmakonts\STL\String\String $contents */
$contents = $value[0];
if (TRUE === ctype_space($contents->value()) || TRUE === $contents->length()->isZero()) {
throw new InvalidDescriptionException();
}
}