Home >Backend Development >PHP Tutorial >php 正则匹配函数体_PHP

php 正则匹配函数体_PHP

WBOY
WBOYOriginal
2016-06-01 12:22:41886browse
复制代码 代码如下:
$data = php_strip_whitespace('test.php'); //去掉注释,空格,换行(不包括字符串中的)
echo $data;
$data = preg_match_all("
/
function\s+ #匹配function和后面的空格
[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* #匹配函数名
\(([^)]*?)\)\s+ #匹配函数参数,并且作为子模式捕获
\{
(.*?)
\}(?=(?:\s*function|\s*?$)) #匹配大括号,仅当后面紧跟着function或者处于字符串结束位置时
/xi
", $data, $matches);

print_r($matches);
?>
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