您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

一种逆天的PHP字符串构造方法

2025/10/1 2:56:32发布12次查看
一种逆天的php字符串构造方法.
虽然php有
/**把一个匿名函数的注释转换为字符串 * @param function $closure 匿名函数 * @param array $replace 替换占位字符的内容,占位字符的格式正则表现为{[0-9]+},比如{0}、{1} 其中数值对应$replace的索引 * @return string 返回匿名函数内的注释内容 */ function string($closure,$replace=null){ $func = new reflectionfunction($closure); $start = $func->getstartline() - 1; $end = $func->getendline() - 1; $filename = $func->getfilename(); $code=implode(, array_slice(file($filename),$start, $end - $start + 1)); $reg=/\\/\\*([^\\0]+)\\*\\//; $match=array(); preg_match($reg,$code,$match); if(count($match)>0){ if(!$replace){ return preg_replace(/\\\\\\\/,\\,preg_replace(/\*(\\\\\/)/, */, trim($match[1]))); } if(count($replace)
用法:
$sql=string(function(){/* select * from table1 t1 left join table2 t2 on t2.id=t1.id where t1.id={0} && t2.name='{1}' */},array(101,ioriliao));
输出结果:
select * from table1 t1left join table2 t2 on t2.id=t1.idwhere t1.id=101 && t2.name='ioriliao'
版权声明:本文为博主原创文章,未经博主允许不得转载。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product