Home >Backend Development >PHP Tutorial >preg_replace_callback Allowed memory error

preg_replace_callback Allowed memory error

WBOY
WBOYOriginal
2016-06-23 13:57:101082browse

服务器PHP Version 5.4.9
preg.php

<?php$content='asdfsadf testtest';$a=123;$content= preg_replace_callback('/<php(\s*?)>(.*?)<\/php(\s*?)>/is', function($match) use($a){return 123;}, $content);echo $content;

运行代码返回:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4169478721 bytes) in /media/raid10/htdocs/xxxx.com/preg.php on line 4

在本地Windows PHP Version 5.3.3
运行代码返回:asdfsadf testtest

哪里出现错误了?


回复讨论(解决方案)

错误提示是说内存不足,而代码本身并没有极度占用内存的成分
可见是一个 bug

而 php 开发组织一再的声明,由于修复了重大漏洞,建议升级至 php5.3.21 或 php5.4.19 以上版本
为什么就是视而不见呢?

楼主,你如何解决这个问题的?好像没有解决方案啊,自己写函数吗?

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