I got it working but its a bit of a cludge - I used [^~] (on the grounds I wont be using ~ in my comments) instead of [.\r\n], for some reason . wasn't working in a character class.
This is what I'm currently using but I'd still like to fix it to be less cludgy.
Ah, too much work. Trust me, I tried before php 5 and I hated it I recall.
I'm pretty sure you said your on php 5+ now right? Look into the 'Reflection' class in php, one of them is the ReflectionFunction, which will drag all the info out for you (where comment is one of its own so long as its /** .. */ style - only two stars at the start).
Try that nancy, you'll love all the other stuff it does too!
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
I'm pretty sure when I used this method I did it in a single regexp. Let me think...
PHP Code:
/**
* Function: MyFunc
* All that fun stuff here
*/
...
PHP Code:
...
$matches = array();
preg_match('/\/\*\*(.*)\*\//ms', $inputStream, $matches);
$i = 0;
foreach ($matches AS $vals)
{
// Yes I see what you're getting at now, this may not work. Thats ok.
if ($i++ == 0)
{
continue;
}
// Do whatever you want but you'll need...
$vals = trim($vals, ' *');
}
Edit:
I see what you mean now oesxyl, this may not work. I'm thinking that the resultant will always have too much data in it.
I just can't remember off hand if I used an ungreedy quantifier on it or not, I'm thinking that I did or I should only get one set of comments which would include tons of code in it as well.
This of course was only for doc style comments (/** ... */), with only the two leading stars (just like the reflection, it would fail if there were more)
Reflection usage (if you have it, its so much easier):
PHP Code:
/**
* some text here
* and some more
* etc
*/
function here()
{
}
/**
* some text here
* and some more
* etc
*/
Now, you can either use the reflection on an individual function, or collect all that are defined:
PHP Code:
// Lets get all the user defined ones by forcing the script to give it to us:
$myComments = array();
$defined = get_defined_functions(); // Built in since php 4.0.4
if (is_array($defined['user']))
{
foreach ($defined['user'] AS $userFunc)
{
$reflect = new ReflectionFunction($userFunc);
$myComments[$userFunc] = var_export($reflect->getDocComment(), 1);
}
}
That should give you an array of your comments with an associative function name in mycomments. There is a whole pile of stuff you can get with Reflection, and its awesome for TDD if you're into that
PHP Code:
<?php
class ReflectionFunction extends ReflectionFunctionAbstract implements Reflector
{
final private __clone()
public void __construct(string name)
public string __toString()
public static string export(string name, bool return)
public string getName()
public bool isInternal()
public bool isDisabled()
public bool isUserDefined()
public string getFileName()
public int getStartLine()
public int getEndLine()
public string getDocComment()
public array getStaticVariables()
public mixed invoke([mixed args [, ...]])
public mixed invokeArgs(array args)
public bool returnsReference()
public ReflectionParameter[] getParameters()
public int getNumberOfParameters()
public int getNumberOfRequiredParameters()
}
?>
Been awhile since I've reflected too, so you may need to tweek it a bit.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
That should give you an array of your comments with an associative function name in mycomments. There is a whole pile of stuff you can get with Reflection, and its awesome for TDD if you're into that
probably are more solution to this problems. I don't look for some parser extensions for php, for example, .
But all this depends of what NancyJ want to achive. If want to build some CASE for php, probably the best solution is reflection.
If only want to extract the comments block, a documenting system, one solution look like mine or better a already build package like doxygen( I don't know if there is a version for windows but I guess it is).
probably are more solution to this problems. I don't look for some parser extensions for php, for example, .
But all this depends of what NancyJ want to achive. If want to build some CASE for php, probably the best solution is reflection.
If only want to extract the comments block, a documenting system, one solution look like mine or better a already build package like doxygen( I don't know if there is a version for windows but I guess it is).
regards
Agreed. PHP is so expansive I don't think I'll ever get to half of the built in stuff, even with 8 years of usage >.<. I suggest reflection simply because I do so much object work now - so easy to build my documentation up, otherwise I'd be too lazy to document my methods, lol.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php