Created
February 27, 2019 08:35
-
-
Save kobus1998/d40817d29d3fd09171735206b420736b to your computer and use it in GitHub Desktop.
Parse docblocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = ' | |
/** | |
* Does something | |
* Some description | |
* | |
* @param string $type | |
* @return string | |
*/ | |
'; | |
preg_match_all('/(?<options>\@\w*\s\w*.*)/', $s, $matches); | |
$options = $matches['options']; | |
$description = trim(str_replace(array_merge($options, ['/', ' * ', '* ', '*']), '', $s)); | |
/* | |
array(2) { | |
[0]=> | |
string(22) "@param string $type | |
" | |
[1]=> | |
string(17) "@return string | |
" | |
} | |
string(32) "Does something | |
Some description" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment