如何解析文档注释 [英] How to parse doc comments

查看:145
本文介绍了如何解析文档注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用反射从一个方法获取文档注释:
http://www.php.net/manual/en/reflectionclass.getdoccomment.php ,其格式如下:

I'm using reflection to get the doc comment from a method: http://www.php.net/manual/en/reflectionclass.getdoccomment.php, which looks like this:

   /** 
    * Method description
    *
    * @param  array $foo    Bla bla
    * @return string        More bla bla
    */

如何将这个字符串解析成我可以使用的东西?
我需要从中提取方法描述文本。其他的东西对我来说不重要,因为我可以使用其他的反射方法来获取参数等。

How can I parse this string into something that I can work with? I need to extract the "Method description" text from it. The other stuff is not important to me, because I can use other reflection methods to get the parameters etc.

推荐答案

trim(str_replace(array('/', '*'), '', substr($rc->getDocComment(), 0, strpos($rc->getDocComment(), '@'))));

假设评论始终采用该格式。

Assuming the comments are always in that format.

这篇关于如何解析文档注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆