|
użytkowników online: 67
|
OPINIE UŻYTKOWNIKÓW
|
Gratulacje i dzięki! Trafiłem tu przypadkiem poszukując informacji na temat php+mysql. Wiele polskich stron powiela identyczne przykłady, klonuje te same kursy i lekcje... ten serwis okazał sie inny. Zasada "problem - rozwiazanie - wyjaśnienie" zdaje egzamin - zapewnia jasną, jednoznaczną i pewną pomoc w konkretnym przypadku. Porady są warte swojej ceny, przede wszystkim ze względu na przyjazną (także dla początkujących) formę i treść oraz bogate i stale powiększane zasoby. Polecam i pozdrawiam!
Kamil Dmowski
Polski Czerwony Krzyż
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
CXXVI. Funkcje Tokenizera
Funkcje tokenizera są interfejsem dostępu do wewnętrznego tokenizera
wbudowanego w silniku Zend. Używając tych funkcji możesz napisać swoje
własne narzędzia do analizy lub modyfikacji kodu PHP bez potrzeby
zajmowania się specyfikacją języka na poziomie analizy leksykalnej.
Patrz także dodatek o tokenach.
Do zbudowania tego rozszerzenia nie są wymagane
żadne zewnętrzne biblioteki.
Począwszy od PHP 4.3.0 funkcje te są dostępne domyślnie. Dla starszych
wersji musisz skonfigurować i skompilować PHP z opcją
--enable-tokenizer. Możesz wyłączyć
wsparcie tokenizera opcją --disable-tokenizer.
PHP w wersji dla systemów
Windows posiada wbudowaną obsługę dla tego rozszerzenia. Nie trzeba ładować
żadnych dodatkowych rozszerzeń aby korzystać z tych funkcji. Notatka:
Wbudowane wsparcie dla tokenizera dostępne jest od PHP 4.3.0.
Poniższe stałe są zdefiniowane w tym rozszerzeniu i stają się dostępne, gdy
rozszerzenie jest dokompilowane do PHP, lub załadowane dynamicznie przy starcie.
Poniżej prosty skrypt PHP używający tokenizera który wczyta plik PHP,
usunie wszystkie komentarze ze źródła i wydrukuje tylko czysty kod.
Przykład 1. Usuwanie komentarzy przy pomocy tokenizera |
<?php
if (!defined('T_ML_COMMENT')) {
define('T_ML_COMMENT', T_COMMENT);
} else {
define('T_DOC_COMMENT', T_ML_COMMENT);
}
$kod = file_get_contents("jakisplik.php");
$tokeny = token_get_all($kod);
foreach ($tokeny as $token) {
if (is_string($token)) {
echo $token;
} else {
list($id, $tekst) = $token;
switch ($id) {
case T_COMMENT:
case T_ML_COMMENT: case T_DOC_COMMENT: break;
default:
echo $tekst;
break;
}
}
}
?>
|
|
- Spis treści
- token_get_all -- Dzieli zadane źródło na tokeny PHP
- token_name -- Zwraca symboliczną nazwę danego tokena PHP
User Contributed Noteslists at 5etdemi dot com
23-Jul-2005 10:33
The tokenizer functions are quite powerful. For example, you can retrieve all of the methods in a given class using an algorithm like:
for each token:
if token is T_FUNCTION then start buffer
if buffer is started then add the current string to the buffer
if token is ( stop buffer
And the great thing is that the class methods will have the right case, so it's a good way to get around the limitations with get_class_methods returning lowercase method names. Also since using a similar algorithm you can read the arguments of a function you can implement Reflections-like functionality into PHP4.
Finally you can use it as a simpler method of extracting Javadoc out of a class file to generate documentation. The util/MethodTable.php class in AMFPHP (http://www.amfphp.org) uses the tokenizer functions to create a method table with all of the arguments, a description, return type, etc. and from that method table it can generate ActionScript that matches the PHP, but it could also be fitted to generate JavaScript, documentation files, or basically anything you put your mind to. I can also see that this could be the base for a class -> WSDL file generator.
|