Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher une fonction PHP

token_get_all

(PHP 4 >= 4.2.0, PHP 5, PHP 7)

token_get_allSplit given source into PHP tokens

Description

token_get_all ( string $source [, int $flags = 0 ] ) : array

token_get_all() parses the given source string into PHP language tokens using the Zend engine's lexical scanner.

For a list of parser tokens, see List of Parser Tokens, or use token_name() to translate a token value into its string representation.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Parameters

source

The PHP source to parse.

flags

Valid flags:

  • TOKEN_PARSE - Recognises the ability to use reserved words in specific contexts.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Return Values

An array of token identifiers. Each individual token identifier is either a single character (i.e.: ;, ., >, !, etc...), or a three element array containing the token index in element 0, the string content of the original token in element 1 and the line number in element 2.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Changelog

Version Description
7.0.0 Added the optional flags parameter along with the TOKEN_PARSE flag.
5.2.2 Line numbers are returned in element 2

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Examples

Example #1 token_get_all() example

<?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;
    }
}
?>

The above example will output something similar to:

Line 1: T_OPEN_TAG ('<?php ')
Line 1: T_ECHO ('echo')
Line 1: T_WHITESPACE (' ')
Line 1: T_CLOSE_TAG ('?>')

Example #2 token_get_all() incorrect usage example

<?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;
    }
}
?>

The above example will output something similar to:

Line 1: T_INLINE_HTML ('/* comment */')
Note in the previous example that the string is parsed as T_INLINE_HTML rather than the expected T_COMMENT. This is because no open tag was used in the code provided. This would be equivalent to putting a comment outside of the PHP tags in a normal file.

Example #3 token_get_all() on a class using a reserved word example

<?php

$source 
= <<<'code'
<?php

class A
{
    const PUBLIC = 1;
}
code;

$tokens token_get_all($sourceTOKEN_PARSE);

foreach (
$tokens as $token) {
    if (
is_array($token)) {
        echo 
token_name($token[0]) , PHP_EOL;
    }
}
?>

The above example will output something similar to:

T_OPEN_TAG
T_WHITESPACE
T_CLASS
T_WHITESPACE
T_STRING
T_CONST
T_WHITESPACE
T_STRING
T_LNUMBER
Without the TOKEN_PARSE flag, the penultimate token (T_STRING) would have been T_PUBLIC.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

See Also

Zoek een PHP-functie

Vertaling niet beschikbaar

De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.

Als je de moed voelt, kun je je vertaling aanbieden ;-)

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-function.token-get-all.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : http://php.net

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut