note 96431 added to reflectionclass.getdoccomment
| From: | leosouza at hotmail dot com | Date: | Fri, 26 Feb 2010 18:10:50 +0000 |
| Subject: | note 96431 added to reflectionclass.getdoccomment | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166401@lists.php.net to get a copy of this message | ||
The code getDocComment() is not as effective as it seems, a method with a well-crafted regular
expression, can solve some problems that this method does not address, for example: Some comments
that begin with "/ *" will not be returned in a file too extensive.
The method below shows how you can use a regular expression to get better results.
This code snippet captures the comments in a file. "Php" and replaces it with an empty
string, ie "cut" the comments of a class:
public function getComments() {
$expr = "/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/";
$filename = $this->fileDir; //file directory
$file = fopen($filename, "r");
$length = filesize($filename);
$comments = fread($file, $length);
preg_match_all($expr, $comments, $matchs); //capture the comments
foreach($matchs[0] as $id => $variable){
$comments = str_replace($variable,'',$comments); // replace the scores of
empty
}
fclose($file);
$file = fopen($filename, "w");
$file = fwrite($file, $comments);
}
----
Server IP: 69.147.83.197
Probable Submitter: 200.225.77.3 (proxied: 127.0.0.1)
----
Manual Page -- http://www.php.net/manual/en/reflectionclass.getdoccomment.php
Edit -- https://master.php.net/note/edit/96431
Del: integrated -- https://master.php.net/note/delete/96431/integrated
Del: useless -- https://master.php.net/note/delete/96431/useless
Del: bad code -- https://master.php.net/note/delete/96431/bad+code
Del: spam -- https://master.php.net/note/delete/96431/spam
Del: non-english -- https://master.php.net/note/delete/96431/non-english
Del: in docs -- https://master.php.net/note/delete/96431/in+docs
Del: other reasons-- https://master.php.net/note/delete/96431
Reject -- https://master.php.net/note/reject/96431
Search -- https://master.php.net/manage/user-notes.php