小弟用正则表达式(?<Class>(?<=\bclass\s)\w+\b)|(?<method>\w+(?=\(\)\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');
}
}
测试的简单代码:
class test{
public fuction success(){
$cid = I(one', 0, haha');
$page = I('getname', 0 ,'getmsg');
$query = I('get.success', blank, '');
}
}
class ceshi{
public fuction chenggong1(){
$cid = I('get.cid', 0, 'intval');
$query = I('get.query', null, '');
$page = I('get.page', 1 ,'intval');;
}
}
用正则表达式测试器测试了一下,发现离我想要的效果还差一点点;
我的问题是:怎么才能令表格中类名和方法名和参数名之间的空格去掉?让他们在同一行?