<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/refs.basic.vartype.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'book.ctype.php',
    1 => 'Ctype',
    2 => 'Character type checking',
  ),
  'up' => 
  array (
    0 => 'refs.basic.vartype.php',
    1 => 'Variable and Type Related Extensions',
  ),
  'prev' => 
  array (
    0 => 'function.trait-exists.php',
    1 => 'trait_exists',
  ),
  'next' => 
  array (
    0 => 'ctype.setup.php',
    1 => 'Installing/Configuring',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ctype/book.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/book.ctype.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="book.ctype" class="book">
 
 <h1 class="title">Character type checking</h1>
 

 <div id="intro.ctype" class="preface">
  <h1 class="title">Introduction</h1>
  <p class="para">
   The functions provided by this extension check whether a character
   or string falls into a certain character class according to the
   current locale (see also <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span>).
  </p>
  <p class="para">
   When called with an integer argument these functions
   behave exactly like their C counterparts from
   <var class="filename">ctype.h</var>.
   It means that if an integer smaller than 256 is passed, it will use the
   ASCII value of it to see if it fits in the specified range (digits are in
   0x30-0x39). If the number is between -128 and -1 inclusive then 256 will
   be added and the check will be done on that.
  </p>
  <div class="warning"><strong class="warning">Warning</strong><p class="para">
As of PHP 8.1.0, passing a non-string argument is deprecated.
In the future, the argument will be interpreted as a string instead of an ASCII codepoint.
Depending on the intended behavior, the argument should either be cast to <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
or an explicit call to <span class="function"><a href="function.chr.php" class="function">chr()</a></span> should be made.</p></div>
  <p class="para">
   When called with a string argument they will check
   every character in the string and will only return
   <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if every character in the string matches the
   requested criteria. When called with an empty string the result will always be <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
  <p class="para">
   Passing anything else but a string or integer will
   return <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> immediately.
  </p>
  <p class="para">
   It should be noted that ctype functions are always preferred over
   regular expressions, and even to some equivalent <code class="literal">&quot;str_*&quot;</code> and <code class="literal">&quot;is_*&quot;</code> functions.
   This is because of the fact that ctype uses a native C library and thus
   processes significantly faster.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    These functions are not related to the Python &quot;ctypes&quot; library at all.
    The extension name stems from the <var class="filename">ctype.h</var> C header
    file that their C equivalents are defined in.
   </p>
   <p class="para">
    This extension also predates Python &quot;ctypes&quot; so any confusion
    caused by this naming is hardly PHP&#039;s fault.
   </p>
  </p></blockquote>
 </div>

 








 








<ul class="chunklist chunklist_book"><li><a href="ctype.setup.php">Installing/Configuring</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="ctype.requirements.php">Requirements</a></li><li><a href="ctype.installation.php">Installation</a></li></ul></li><li><a href="ref.ctype.php">Ctype Functions</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="function.ctype-alnum.php">ctype_alnum</a> — Check for alphanumeric character(s)</li><li><a href="function.ctype-alpha.php">ctype_alpha</a> — Check for alphabetic character(s)</li><li><a href="function.ctype-cntrl.php">ctype_cntrl</a> — Check for control character(s)</li><li><a href="function.ctype-digit.php">ctype_digit</a> — Check for numeric character(s)</li><li><a href="function.ctype-graph.php">ctype_graph</a> — Check for any printable character(s) except space</li><li><a href="function.ctype-lower.php">ctype_lower</a> — Check for lowercase character(s)</li><li><a href="function.ctype-print.php">ctype_print</a> — Check for printable character(s)</li><li><a href="function.ctype-punct.php">ctype_punct</a> — Check for any printable character which is not whitespace or an
   alphanumeric character</li><li><a href="function.ctype-space.php">ctype_space</a> — Check for whitespace character(s)</li><li><a href="function.ctype-upper.php">ctype_upper</a> — Check for uppercase character(s)</li><li><a href="function.ctype-xdigit.php">ctype_xdigit</a> — Check for character(s) representing a hexadecimal digit</li></ul></li></ul></div><?php manual_footer($setup); ?>