preg_replace_callback函数解决方案

WBOY
Release: 2016-06-13 11:50:35
Original
844 people have browsed it

preg_replace_callback函数

$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(<br />        '/\[([^\[\]]*)\]/is',<br />        function ($matches) {<br />            return '.'.str_replace('$','\$',$matches[1]);<br />        },<br />        $val<br />    );<br />echo $val;
Copy after login

------解决方案--------------------
引用:
最后一处了 这里中间的代码 include哪一行不清楚怎么改
<br />$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s';<br />$replacement = "'{include file='.strtolower('\\1'). '}'";<br />$source = preg_replace_callback($pattern, $replacement, $source);
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!