Wez Furlong wrote:
If you name the token __HALT_PHP_PARSER__ instead (or something
equally unlikely to be used by accident and unambiguous in meaning),
you'll get a +1 from me :-)

I aim to please ;-) Here is the revised patch that makes the token a bit clearer and also increases the strictness of the parser. For those of you wondering how would you quickly locate the end of script and start of data here are some solutions:


1) while (fgets($fp) != '<?php __HALT_PHP_PARSER__; ?>'));
2) Assuming the author knows the maximum length of the actual code, they could read X bytes and then using strpos locate the position of the HALT token and start reading data dump from there.
$fp = fopen(__FILE__, "r");
$halt_token = "<?php "."__HALT_PHP_PARSER__"."; ?>";
$pos = strpos(fread($fp, 10000), $halt_token);
fseek($fp, $pos + strlen($halt_token));


Ilia
Index: Zend/zend_language_scanner.l
===================================================================
RCS file: /repository/ZendEngine2/zend_language_scanner.l,v
retrieving revision 1.124
diff -u -a -p -r1.124 zend_language_scanner.l
--- Zend/zend_language_scanner.l        7 Mar 2005 16:48:49 -0000       1.124
+++ Zend/zend_language_scanner.l        11 Mar 2005 21:53:04 -0000
@@ -1342,6 +1342,10 @@ NEWLINE ("\r"|"\n"|"\r\n")
        return T_INLINE_HTML;
 }
 
+<INITIAL>"<?php __HALT_PHP_PARSER__; ?>" {
+       yyterminate();
+}
+
 
<INITIAL>"<?"|"<script"{WHITESPACE}+"language"{WHITESPACE}*"="{WHITESPACE}*("php"|"\"php\""|"\'php\'"){WHITESPACE}*">"
 {
        HANDLE_NEWLINES(yytext, yyleng);
        if (CG(short_tags) || yyleng>2) { /* yyleng>2 means it's not <? but 
<script> */

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to