Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created February 27, 2019 08:35
Show Gist options
  • Save kobus1998/d40817d29d3fd09171735206b420736b to your computer and use it in GitHub Desktop.
Save kobus1998/d40817d29d3fd09171735206b420736b to your computer and use it in GitHub Desktop.
Parse docblocks
<?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