Home > Backend Development > PHP Tutorial > preg_replace_callback函数

preg_replace_callback函数

WBOY
Release: 2016-06-23 14:00:58
Original
1057 people have browsed it

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

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


回复讨论(解决方案)

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

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

同理这个呢

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

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

同理这个呢

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

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


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

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

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

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

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








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

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



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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template