各位大神,小弟有个用正则表达式获取信息的问题~!
我这里有一段代码,把代码当成文本。我需要获取下列代码的类名,方法名,参数,而且参数对应方法,方法对应类
就是说,通过正则表达式,我想要知道这段代码里面有哪些class,这些class里面有哪些方法,这些方法里面有哪些参数
这是我写的三条正则表达式:
查找类:(?<Class>(?<=\bclass\s)\w+\b)
查找方法: (?<method>(?<=function ).*(?=\s*\{\s*))
查找参数: (?<parameter>(?<=I\().*(?=\)))
但是我不知道怎么把他们整合成一条表达式..........
然后下面是代码。希望知道怎么实现的人能写给我看一下。或者大家有什么其他的方法可以实现这样的功能的话也希望能写出来让我看一下,谢谢~!
<?php
namespace Home\Controller;
use Home\Model\ArticleCategoriesModel;
use Home\Model\ArticlesModel;
use Think\Controller;
use Home\Model;
class ArticlesController extends BaseController
{
protected $article_categories_model;
protected $articles_model;
public function __construct(){()
parent::__construct();
$authorize_controller = new AuthorizeController();
$authorize_controller->validate();
$this->article_categories_model = new ArticleCategoriesModel($this->logs_model, $this->error_stack);
$this->articles_model = new ArticlesModel($this->logs_model, $this->error_stack);
}
public function getSubCategories()
{
$rank = I('get.rank', 0, null);
$result = $this->article_categories_model->getTypesByRank($rank);
if ($result === false) {
$this->ajaxRespondError($this->error_stack->getLastErrorCode(), '获取文案类目失败');
}
if(is_array($result) && !count($result)){
//若子分类不存在则可能是最底层分类,则尝试查询文案分类
if ($last_sect = strrchr($rank,'_')){
$cid = substr($last_sect,1);
} else {
$cid = $rank;
}
$result = $this->articles_model->getArticlesByCid($cid);
if($result === false){
$this->ajaxRespondError($this->error_stack->getLastErrorCode(), '获取文案列表失败');
}
}
$this->ajaxRespond($result, 'json');
}
public function getArticlesList()
{
$cid = I('get.cid', 0, 'intval');
$page = I('get.page', 1 ,'intval');
$query = I('get.query', null, '');
$result = $this->articles_model->getArticlesByCid($cid, $page, $query);
if ($result === false) {
$this->ajaxRespondError($this->error_stack->getLastErrorCode(), '获取文案列表失败');
}
$this->ajaxRespond($result, 'json');
}
}
这是一段php代码,但是把它看成普通文本就好了。