Well, firstly the common splitting identifier is the *, so firstly I would explode by them:
$segments = explode('*', $text);
Then I see that there will be spaces because at the sides of the * we have spaces, so they need to be trimmed away, but firstly we need to set up a blank array to store the new cleaned data in.
$results = array();
Then loop through each segment, trimming and check for the @ symbol:
$first = true;
foreach($segments as $segment) {
// Strip trailing/leading whitespace and line breaks
$segment = trim(segment);
if ($first === true) {
// Name: The very first line would be the name.
$results['name'] = $segment;
$first = false;
} else {
// Params and return
if ($segment[0] === "@") {
// Find the first space, usually after @xxxx text
$pos = strpos(' ', $segment);
// Get the name of the var so param for @param
$index = substr($segment, 1, $pos);
// rest of the string
$value = substr($segment, $pos+1);
switch($index) {
case 'param':
case 'params':
$results['params'][] = $value;
break;
case 'return':
case 'returns':
$params['return'] = $value;
break;
default:
$params[$index] = $value;
break;
}
}
}
}
Hopefully you will be able to see what this code bock is doing, but if not a little explanation below.
After exploding the string into segments, we start looping through them. There's a small $first variable that is set to true as default so we know if it's the first iteration of the array, the reason being the first line is the function name and it does not have have an @ symbol to denote a named line.
After that, we check to see if the character at index 0 is equal to @. If so, then we cut out the string so that:
@param fun ...
0123456789 ...
^ ^
So that we cut from 1 to the index if the space (6) and this would give 'param'.
After creating a switch statement, we just use substr() to cut off only the part of the string after the param prefix (offset 6 in this case).
This code more than likely will not work as it's untested, but it's written to show you how to go about it. I hope it gets you going.
Some other resources:
I really don't think a regular expression is the way to go, but if that's really what you want to do then [How to parse a phpDoc style comment block with PHP?][6] is the way to go.