token_get_all()函数

token_get_all

(PHP 4 >= 4.2.0, PHP 5)

token_get_all — 将提供的源码按 PHP 标记进行分割,可以用作php源代码的压缩,会按照固定的分解方法,分解php代码成不同的部分

说明

array token_get_all ( string $source )

token_get_all() 解析提供的 source 源码字符,然后使用 Zend 引擎的语法分析器获取源码中的 PHP 语言的解析器代号

解析器代号列表见解析器代号列表, 或者使用 token_name() 翻译获取这个代号的字符串表示.

参数

source

需要解析的 PHP 源码.

返回值

array

  

 1 <?php
 2 $tokens = token_get_all('<?php echo; ?>'); /* => array(
 3                                                   array(T_OPEN_TAG, '<?php'), 
 4                                                   array(T_ECHO, 'echo'),
 5                                                   ';',
 6                                                   array(T_CLOSE_TAG, '?>') ); */
 7 
 8 /* Note in the following example that the string is parsed as T_INLINE_HTML
 9    rather than the otherwise expected T_COMMENT (T_ML_COMMENT in PHP <5).
10    This is because no open/close tags were used in the "code" provided.
11    This would be equivalent to putting a comment outside of <?php ?> tags in a normal file. */
12 $tokens = token_get_all('/* comment */'); // => array(array(T_INLINE_HTML, '/* comment */'));
13 ?>
原文地址:https://www.cnblogs.com/gophper/p/4397463.html