原创日志

正则批量替换函数preg_replace_callback 在php5.2 php5.3中的类中使用问题相关说明

[ 2020-06-09 21:54:10 | 作者: admin ]
字号: | |
p.s. 真的挺奇怪,这么常用的函数,关于类中使用网上居然很难找到有用相关资料,难道大伙都避免使用preg_replace_callback吗。有用的说明请看参考1.

下面举例说明,其中 next_year 为回调函数
function next_year($matches) { 
           // 通常:$matches[0] 是完整的匹配项,$matches[1] 是第一个括号中的子模式的匹配项, 以此类推
           return $matches[1].($matches[2]+1); 
  } 

php5.2和php5.3的类中都可以使用的标准方法:
preg_replace_callback(”|(d{2}/d{2}/)(d{4})|”,array( &$this, ‘next_year’), $str);

php5.3的类中还可以使用方法:
preg_replace_callback(”|(d{2}/d{2}/)(d{4})|”,"self::next_year", $str);


php5.2和PHP5.3的非类中使用方法:
preg_replace_callback(”|(d{2}/d{2}/)(d{4})|”,"next_year", $str);



参考:
preg_replace_callback()调用类中的回调函数
https://blog.csdn.net/eroslp/article/details/6172597

preg_replace_callback 在php5.2的问题
https://www.yezismile.com/index/titleinfo/id/433

preg_replace_callback(): Requires argument 2
https://blog.csdn.net/crabdave/article/details/84810312
[最后修改由 admin, 于 2021-01-23 10:52:16]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=2687

这篇日志没有评论。

此日志不可发表评论。