preg_replace 反向引用日期函数
PHP 5.2.15
我试图用日期函数替换 {date[F]} 。
我有一个效果很好的模式。
preg_replace('/({date\[(.*?)\]})/', date(${2}), $subject);
我已经尝试过 preg_replace_callback 但即使当我使用 create_function() 时它似乎也不起作用,
我尝试的方法大多出现未定义的错误。
PHP 5.2.15
I am trying to replace {date[F]} with the date function.
I have the pattern which works great.
preg_replace('/({date\[(.*?)\]})/', date(${2}), $subject);
I have tried preg_replace_callback but it doesn't seem to work even when I use create_function()
I get mostly undefined errors on my methods tried.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实需要
/e
修饰符。并且替换表达式必须是字符串:请注意,您还忘记转义第一个
{
大括号。请参阅
preg_replace
#105490 的手动示例。或者preg_replace_callback
回调必须如何解压匹配参数(这听起来像是您原来的问题)。You do need the
/e
modifier. And the replacement expression must be a string:Note that you also forgot to escape the first
{
curly brace.See the manual examples for
preg_replace
#105490. Or howpreg_replace_callback
callbacks must unpack the match parameter (which sounds like your original issue).