Home >Backend Development >PHP Tutorial >preg_replace改成preg_replace_callback

preg_replace改成preg_replace_callback

WBOY
WBOYOriginal
2016-06-23 13:25:031141browse

preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $value);
正则不怎么懂


回复讨论(解决方案)

preg_replace_callback('!s:(\d+):"(.*?)";!s', function($m) { return 's:'.strlen($m[2]).":\"$m[2]\";";}, $value);

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