Home > Backend Development > PHP Tutorial > preg_replace怎么替换成preg_replace_callback

preg_replace怎么替换成preg_replace_callback

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:05:07
Original
1214 people have browsed it

preg_replace如何替换成preg_replace_callback
小弟以前从事Delphi开发,被社会所迫学习了PHP,今天当头一棒直接蒙了。
这个怎么改啊,程序报错需要将preg_replace替换成preg_replace_callback

$fields = preg_replace('/([a-zA-Z0-9_]+)\.([a-zA-Z0-9_*]+)/e', "\$this->_getFieldTable('\\1') . '.\\2'", $fields);
Copy after login

------解决方案--------------------
$fields = preg_replace_callback('/([a-zA-Z0-9_]+)\.([a-zA-Z0-9_*]+)/', array($this, "_getFieldTable"), $fields);

不过_getFieldTable要改一下了,因为接收的是一个数组了。

------解决方案--------------------
噢,漏了个点
$fields = preg_replace('/([a-zA-Z0-9_]+)\.([a-zA-Z0-9_*]+)/', function($r) {<br />  return $this->_getFieldTable($r[1]) . ".$r[2]"; <br /> }, $fields);
Copy after login

Related labels:
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