A php string construction method against the day. although PHP has the usage of multi-line strings such as & lt;, it is uncomfortable to use because the last end line cannot be empty & #26684 ;. Let's take a look at the string construction method I wrote. the code is as follows: ** convert an anonymous function annotation to a string * @ paramfunction $ closure anonymous function * @ paramarray $ replace a PHP string construction method against the day.
Although PHP has < <这种多行字符串的用法,但用着不爽啊,因为最后的结束行不能有空格。看看我写的这种字符串构造方法吧,代码如下:< p>
/** Convert the annotation of an anonymous function to the string * @ param function $ closure anonymous function * @ param array $ replace to replace the placeholder character content, the regular expression of placeholder characters is {[0-9] + }, for example, in {0} and {1}, the value corresponds to the $ replace Index * @ return string and returns the comments in the anonymous function */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), $ star T, $ 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) <= 0) {return preg_replace ("/\\\\\\\/", "\\", preg_replace ("/\*(\\\\\/)/", "*/", trim ($ match [1]);} $ tmp1 = $ match [1]; for ($ I = 0; $ I
Usage:
$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"));
Output result:
select * from table1 T1left join table2 T2 on T2.id=T1.idwhere T1.id=101 && T2.name='ioriliao'
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.