PHP token_get_all() Function Last Updated : 25 Aug, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The token_get_all() function is an inbuilt function in PHP that is used to tokenize a given PHP source code string into an array of tokens. This function is particularly useful for analyzing, parsing, or manipulating PHP code programmatically. Syntax: token_get_all(string $code, int $flags = 0)Parameters: This function accepts two parameters that are described below. $code: This is the string that is going to tokenize.$flags: This is an optional parameter that modifies the tokenization behavior of the string.Return Values: The token_get_all() returns array contains elements where each element represents a token. Program 1: The following program demonstrates the token_get_all() function. PHP <?php $code = '<?php echo "Hello, world!"; ?>'; $tokens = token_get_all($code, TOKEN_PARSE); foreach ($tokens as $token) { if (is_array($token)) { echo "Token: " . token_name($token[0]) . " - Content: " . $token[1] . "\n"; } else { echo "Token: " . $token . "\n"; } } ?> OutputToken: T_OPEN_TAG - Content: <?php Token: T_ECHO - Content: echo Token: T_WHITESPACE - Content: Token: T_CONSTANT_ENCAPSED_STRING - Content: "Hello, world!" Token: ; Token: T_WHITESPACE - Content: ...Program 2: The following program demonstrates the token_get_all() function. PHP <?php $code = '<?php $message = "Hello, "; $name = "John"; echo $message . $name; ?>'; $tokens = token_get_all($code); foreach ($tokens as $token) { if (is_array($token)) { list($tokenId, $tokenContent) = $token; echo "Token: " . token_name($tokenId) . " - Content: " . $tokenContent . "\n"; } else { echo "Token: " . $token . "\n"; } } ?> OutputToken: T_OPEN_TAG - Content: <?php Token: T_WHITESPACE - Content: Token: T_VARIABLE - Content: $message Token: T_WHITESPACE - Content: Token: = Token: T_WHITESPACE - Content: Token: T_CONSTAN...Reference: https://www.php.net/manual/en/function.token-get-all.php Comment More infoAdvertise with us Next Article PHP | stream_get_filters() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function Similar Reads PHP | stream_get_filters() Function The stream_get_filters() function is an inbuilt function in PHP which is used to get the list of registered stream filters. Syntax: array stream_get_filters( void ) Parameters: This function does not accept any parameter. Return Value: This function returns an array containing the name of all availa 1 min read PHP get_resources() Function The get_resources() function is an inbuilt function in PHP that returns active resources in an array form, & optionally, the resource type will be filtered. Syntax: array get_resources(?string $type = null)Parameters: This function accepts one parameter that is described below: type: This parame 1 min read PHP func_get_arg() Function The func_get_arg() function is an inbuilt function in PHP which is used to get a mentioned value from the argument passed as the parameters. Syntax: mixed func_get_arg( int $arg ) Parameters: This function accepts a single parameter as mentioned above and described below. $arg: This parameter holds 2 min read PHP ob_get_clean() Function The ob_get_clean() function is an in-built PHP function that is used to clean or delete the current output buffer. It's also used to get the output buffering again after cleaning the buffer. The ob_get_clean() function is the combination of both ob_get_contents() and ob_end_clean(). Syntax: string|f 2 min read PHP DsSet get() Function The Ds\Set::get() function of Ds\Set class in PHP is an inbuilt function which is used to get a value from the Set instance. This function is used to fetch a value present at a particular index in the Set instance. Syntax: mixed public Ds\Set::get ( int $index ) Parameters: This function accepts a s 2 min read PHP func_get_args() Function The func_get_args() Â is an inbuilt function in PHP that is used to get a function argument list in an array form. This function is similar to func_get_arg(). Syntax: array func_get_args()Parameters: This function does not accept any parameter. Return Value: This method returns an array, where a copy 1 min read Like