2015-11-03 103 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