Home >Backend Development >PHP Tutorial >preg_replace_callback函数

preg_replace_callback函数

WBOY
WBOYOriginal
2016-06-23 14:00:581061browse

$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);

这一句 用preg_replace_callback函数怎么改写呢 求指教下 


回复讨论(解决方案)

$val = preg_replace_callback("/\[([^\[\]]*)\]/eis", function($match){ return str_replace('$','\$',$match)}, $val);

$val = preg_replace_callback(        '/\[([^\[\]]*)\]/is',        function ($matches) {            return '.'.str_replace('$','\$',$matches[1]);        },        $val    );echo $val;

同理这个呢

$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";

求说一下改的基本思想  还是不太懂 谢谢了 

同理这个呢

$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";

求说一下改的基本思想  还是不太懂 谢谢了 


这个已改好 依葫芦画瓢的 = =
$out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($ro) { return stripslashes(trim($ro[1],'\''));}, var_export($t, true)) . ";\n";

最后一处了 这里中间的代码 include哪一行不清楚怎么改

$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s';$replacement = "'{include file='.strtolower('\\1'). '}'";$source = preg_replace_callback($pattern, $replacement, $source);
- -

最后一处了 这里中间的代码 include哪一行不清楚怎么改

$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s';$replacement = "'{include file='.strtolower('\\1'). '}'";$source = preg_replace_callback($pattern, $replacement, $source);
- -
还是一样的 也还是一字符串啊 还是原来的方式就行了








最后一处了 这里中间的代码 include哪一行不清楚怎么改

$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s';$replacement = "'{include file='.strtolower('\\1'). '}'";$source = preg_replace_callback($pattern, $replacement, $source);
- -
还是一样的 也还是一字符串啊 还是原来的方式就行了



主要是这一会不会改了,可以帮我改改看么 就最短的这句
$replacement = "'{include file='.strtolower('\\1'). '}'";
  非常感谢

$replacement = function ($matches) { return '{include file='.strtolower($matches[1]). '}';};

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn