There is a function here token_get_all($code)that can be used for this and is more reliable than you might think.
Here is a sample code to get all comments from a file (it has not been verified, but should be enough for you to get started):
<?php
$source = file_get_contents( "file.php" );
$tokens = token_get_all( $source );
$comment = array(
T_COMMENT,
T_ML_COMMENT,
T_DOC_COMMENT
);
foreach( $tokens as $token ) {
if( !in_array($token[0], $comment) )
break;
$txt = $token[1];
}
?>
svens source
share