<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.phptoken.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'phptoken.tokenize.php',
    1 => 'PhpToken::tokenize',
    2 => 'Splits given source into PHP tokens, represented by PhpToken objects.',
  ),
  'up' => 
  array (
    0 => 'class.phptoken.php',
    1 => 'PhpToken',
  ),
  'prev' => 
  array (
    0 => 'phptoken.tostring.php',
    1 => 'PhpToken::__toString',
  ),
  'next' => 
  array (
    0 => 'ref.tokenizer.php',
    1 => 'Tokenizer 函数',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/tokenizer/phptoken/tokenize.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="phptoken.tokenize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PhpToken::tokenize</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">PhpToken::tokenize</span> &mdash; <span class="dc-title">Splits given source into PHP tokens, represented by PhpToken objects.</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-phptoken.tokenize-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>PhpToken::tokenize</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$code</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Returns an array of PhpToken objects representing given <code class="parameter">code</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phptoken.tokenize-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
     <dt><code class="parameter">code</code></dt>
     <dd>
      <p class="para">
       The PHP source to parse.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Valid flags:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <strong><code><a href="tokenizer.constants.php#constant.token-parse">TOKEN_PARSE</a></code></strong> - Recognises the ability to use
          reserved words in specific contexts.
         </span>
        </li>
       </ul>
      </p>
     </dd>
    
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-phptoken.tokenize-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An array of PHP tokens represented by instances of PhpToken or its descendants.
   This method returns <span class="type">static[]</span> so that PhpToken can be seamlessly extended.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-phptoken.tokenize-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #1 <span class="function"><strong>PhpToken::tokenize()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$tokens </span><span style="color: #007700">= </span><span style="color: #0000BB">PhpToken</span><span style="color: #007700">::</span><span style="color: #0000BB">tokenize</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;?php echo; ?&gt;'</span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$tokens </span><span style="color: #007700">as </span><span style="color: #0000BB">$token</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Line </span><span style="color: #007700">{</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">line</span><span style="color: #007700">}</span><span style="color: #DD0000">: </span><span style="color: #007700">{</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTokenName</span><span style="color: #007700">()}</span><span style="color: #DD0000"> ('</span><span style="color: #007700">{</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">text</span><span style="color: #007700">}</span><span style="color: #DD0000">')"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例会输出：</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Line 1: T_OPEN_TAG (&#039;&lt;?php &#039;)
Line 1: T_ECHO (&#039;echo&#039;)
Line 1: ; (&#039;;&#039;)
Line 1: T_WHITESPACE (&#039; &#039;)
Line 1: T_CLOSE_TAG (&#039;?&gt;&#039;)</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>示例 #2 Extending PhpToken</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">MyPhpToken </span><span style="color: #007700">extends </span><span style="color: #0000BB">PhpToken </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">getUpperText</span><span style="color: #007700">() {<br />        return </span><span style="color: #0000BB">strtoupper</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">text</span><span style="color: #007700">);<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$tokens </span><span style="color: #007700">= </span><span style="color: #0000BB">MyPhpToken</span><span style="color: #007700">::</span><span style="color: #0000BB">tokenize</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;?php echo; ?&gt;'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"'</span><span style="color: #007700">{</span><span style="color: #0000BB">$tokens</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">getUpperText</span><span style="color: #007700">()}</span><span style="color: #DD0000">'"</span><span style="color: #007700">;</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例会输出：</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">&#039;&lt;?PHP &#039;</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-phptoken.tokenize-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.token-get-all.php" class="function" rel="rdfs-seeAlso">token_get_all()</a> - 将提供的源码按 PHP 标记进行分割</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>