Home  >  Article  >  Backend Development  >  PHP 正则 中遇到的一个小疑点, 卡死,执行慢

PHP 正则 中遇到的一个小疑点, 卡死,执行慢

WBOY
WBOYOriginal
2016-06-13 11:53:191020browse

PHP 正则 中遇到的一个小问题, 卡死,执行慢

找到问题所在很麻烦,但问题本身很简单


我用一个正则来判断 一段文本是否是JSONP格式.  结果是程序卡死(很慢).


加了许多调试信息,最终确定是preg_match语句


再查看细节, 文本长度180K.   正则看来是无法处理这么长的内容. 


解决方案就简单了,用字符串查找和截取 代替正则.


总结 : 正则很方便,但不是在所有情况下都可行的.  大文本时请注意.

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