Take the parsing annotation configuration in crossphp as an example to define the protocol name: annotate $ str_codearray (foobar); stream_register_wrapper (annotate, stringToPHPStream); $ varinclude (annotate: {$ str_code }); print_r ($ var); the string $ str_code becomes a php array. Stay away from eval, cool.
Take the parsing annotation configuration in crossphp as an example to define the protocol name: annotate $ str_code = array (foo = bar); stream_register_wrapper (annotate, stringToPHPStream); $ var = include (annotate: // {$ str_code}); print_r ($ var); then the string $ str_code becomes a php array. Stay away from eval, cool.
Take the parsing annotation configuration in crossphp as an example to define the protocol name: annotate
$ Str_code = 'array ("foo" => "bar ")';
Stream_register_wrapper ("annotate", "stringToPHPStream ");
$ Var = include ("annotate: // {$ str_code }");
Print_r ($ var );
In this way, the string $ str_code becomes a php array. Stay away from eval, cool ~
To change the protocol name in the example, change the stream_open method CrossPHP in the stringToPHPStream class.
"bar")';stream_register_wrapper("annotate", "stringToPHPStream");$var = include ("annotate://{$str_code}");print_r($var);
* Usage method stream_register_wrapper ("custom name", "stringToPHPStream") * $ var = include ("custom name: // string Code ")*** @ Auth: wonli * Class StringToPHPStream * @ package Cross \ Lib \ Other */class StringToPHPStream {/*** code content ** @ var array */static $ content; /*** mark in $ content ** @ var string */protected $ key;/*** @ var int */protected $ pos; /*** @ param $ path * @ param $ mode * @ param $ options * @ param $ opened_path * @ return bool */public function stream_open ($ path, $ mode, $ options, $ opened_path) {$ this-> key = md5 ($ path ); If (! Isset (self ::$ content [$ this-> key]) {self ::$ content [$ this-> key] = sprintf (' Pos = 0; return true;}/*** @ param $ count * @ return string */public function stream_read ($ count) {$ content = self :: $ content [$ this-> key]; $ ret = substr ($ content, $ this-> pos, $ count ); $ this-> pos + = strlen ($ ret); return $ ret;}/*****/public function stream_stat () {}/ ****/public function stream_eof (){}}