以crossphp中解析注释配置为例,定义协议名:annotate $str_code = array(foo=bar); stream_register_wrapper(annotate,stringToPHPStream); $var=include(annotate://{$str_code}); print_r($var); 这样字符串$str_code就变成了一个php的array,远离eval吧,骚年
以crossphp中解析注释配置为例,定义协议名:annotate
<?php
include __DIR__.'/stringToPHPStream.php';
$str_code = 'array("foo"=>"bar")';
stream_register_wrapper("annotate", "stringToPHPStream");
$var = include ("annotate://{$str_code}");
print_r($var);<?php
/**
* 字符串php代码通过wrapper转换为可以执行的php代码
* <pre class="brush:php;toolbar:false;">
* 使用方式 stream_register_wrapper("自定义名字", "stringToPHPStream")
* $var = include ("自定义名字://字符串代码")
*
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号