dp5657087
dp5657087
2016-06-28 04:39

用preg_replace_callback替换preg_replace仍然失败

  • php

I'm working on porting SocialEngine to work on PHP7.

On the default install I get the following error:

preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in 
<b>/home/vagrant/code/mysite/project/app/application/libraries/Scaffold/modules/NestedSelectors/NestedSelectors.php</b>
on line <b>300</b>

The code for that error looks like so:

$xml = preg_replace('/([-_A-Za-z*]+)\s*:\s*([^;}{]+)(?:;)/ie', "'<property name=\"'.trim('$1').'\" value=\"'.trim('$2').'\" />
'", $xml);

I replaced it with preg_replace_callback like so:

$xml = preg_replace_callback('/([-_A-Za-z*]+)\s*:\s*([^;}{]+)(?:;)/ie', function($matches) {
    return "'<property name=\"'.trim('$matches[1]').'\" value=\"'.trim('$matches[2]').'\" />
'";
}, $xml);

and now I get this error:

preg_replace_callback(): The /e modifier is no longer supported, use preg_replace_callback instead in 
<b>/home/vagrant/code/mysite/project/app/application/libraries/Scaffold/modules/NestedSelectors/NestedSelectors.php</b> 
on line <b>304</b>

This seems valid to me, what have I done wrong?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答