2015-11-03 80 views
1

我有使用preg_match一些问题,而不是选择1件事。它从第一个开始到最后一个结束。PHP preg_match只有一个匹配

preg_match('/@section\(\'(.*)\'\)(.*)@endsection/s', $content,$results 

$内容:

@section('title') 

Number 1 

@endsection 

@section('content') 

Number 2 

@endsection 

但是,当我使用的preg_match,结果出来,如:

Number 1 

@endsection 

@section('content') 

Number 2 

回答

2

你在这里等作为

寻找非贪婪量词
/@section\(\'(.*?)\'\)(.*?)@endsection/s 
       //^^  ^^ 

Regex