
- PHP Tutorial
- PHP - Home
- PHP - Introduction
- PHP - Environment Setup
- PHP - Syntax Overview
- PHP - Variable Types
- PHP - Constants
- PHP - Operator Types
- PHP - Decision Making
- PHP - Loop Types
- PHP - Arrays
- PHP - Strings
- PHP - Web Concepts
- PHP - GET & POST
- PHP - File Inclusion
- PHP - Files & I/O
- PHP - Functions
- PHP - Cookies
- PHP - Sessions
- PHP - Sending Emails
- PHP - File Uploading
- PHP - Coding Standard
- Advanced PHP
- PHP - Predefined Variables
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Bugs Debugging
- PHP - Date & Time
- PHP & MySQL
- PHP & AJAX
- PHP & XML
- PHP - Object Oriented
- PHP - For C Developers
- PHP - For PERL Developers
- PHP Form Examples
- PHP - Form Introduction
- PHP - Validation Example
- PHP - Complete Form
- PHP login Examples
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP AJAX Examples
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML Example
- PHP - XML Introduction
- PHP - Simple XML
- PHP - Simple XML GET
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Frame Works
- PHP - Frame Works
- PHP - Core PHP vs Frame Works
- PHP Design Patterns
- PHP - Design Patterns
- PHP Function Reference
- PHP - Built-In Functions
- PHP Useful Resources
- PHP - Questions & Answers
- PHP - Useful Resources
- PHP - Discussion
PHP - token_get_all() Function
token_get_all() function can split a given source into PHP tokens.
Syntax
array token_get_all( string $source [, int $flags = 0 ] )
token_get_all() function can parse a given source string into PHP language tokens by using the Zend engine's lexical scanner. For a list of parser tokens, we can use the token_name() function to translate a token value into its string representation.
token_get_all() function can return an array of token identifiers. Each individual token identifier is either a single character (i.e.:;, ., >, ! etc...), or a three-element array containing token index in element 0, string content of an original token in element 1, and line number in element 2.
Example-1
<?php $tokens = token_get_all("<?php echo; ?>"); foreach($tokens as $token) { if(is_array($token)) { echo "Line {$token[2]}: ", token_name($token[0]), " ('{$token[1]}')", PHP_EOL; } } ?>
Example-2
<?php $tokens = token_get_all("/* comment */"); foreach($tokens as $token) { if(is_array($token)) { echo "Line {$token[2]}: ", token_name($token[0]), " ('{$token[1]}')", PHP_EOL; } } ?>
Example-3
<?php $source = <<<"code" <?php class A { const PUBLIC = 1; } code; $tokens = token_get_all($source, TOKEN_PARSE); foreach($tokens as $token) { if(is_array($token)) { echo token_name($token[0]) , PHP_EOL; } } ?>
php_function_reference.htm
Advertisements