鍍金池/ 問答/Java  PHP/ PHP 正則怎樣獲取php文件內(nèi)的注釋內(nèi)容?

PHP 正則怎樣獲取php文件內(nèi)的注釋內(nèi)容?

clipboard.png

如圖所示,我想要將注釋拿下來生成api文檔,各位大神幫幫忙!??!

回答
編輯回答
話寡

3種方案
1、反射
2、正則,如:https://github.com/jilieryuyi... (純文件分析生成文檔,就是基于正則表達式的)
3、開源項目 https://www.phpdoc.org/

2017年4月11日 23:01
編輯回答
情已空

phpdoc

2018年9月20日 15:26
編輯回答
喵小咪

反射就行了,然后取到注釋之后,再使用正則提取你想要的各部分內(nèi)容

2017年12月6日 01:11
編輯回答
爆扎

如果是這種/xxx/多行注釋,直接

<?php
$code = file_get_contents('index.php');
if (preg_match_all('|/\*(.*)\*/|isU', $code, $matches)){
    print_r($matches);
}

clipboard.png

目測無問題

2018年7月22日 20:02
編輯回答
傻叼

推薦你直接使用swagger吧

2017年1月9日 08:43
編輯回答
筱饞貓

根據(jù) @老鼠擰刀滿街找貓 提供的正則改的,生成txt文件的api文檔。

正則: /(\/\*{2})([\s\S]*)(\*\/)/U

        $data = file_get_contents(dirname(__FILE__)."/WorkController.class.php");
        preg_match_all('/(\/\*{2})([\s\S]*)(\*\/)/U',$data,$match);
        $file=fopen("api.txt","a");

        foreach ($match[0] as $ma){
            preg_match_all("/@.*?/U",$ma,$da);
            fwrite($file,"===================\r\n");
           foreach ($da[0] as $d){
               fwrite($file,$d."\r\n");
           }
            fwrite($file,"===================\r\n\r\n\r\n");
        }

        fclose($file);
2018年8月29日 01:37
編輯回答
扯不斷
/\*([\s\S]*?)\*/
2017年7月30日 17:29