Search code examples
phpstringreflectioncomments

How to parse doc comments


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.


Solution

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

    Assuming the comments are always in that format.