2017-01-02 83 views
1

我有這樣的字符串,我需要把它分解使用reqular表達正則表達式/##if##(.*?)(.*?)##end_if##/s

<?php 
$matches = null; 
$returnValue = preg_match('/##if##(.*?)(.*?)##end_if##/s', '##if## 
    First Conditions 
    ##if## 
    First sub Conditions 
    ##end_if## 
##end_if## 

##if## 
    Second Conditions 
##end_if##', $matches); 

結果是

array (
    0 => '##if## 
    First Conditions 
    ##if## 
    First sub Conditions 
    ##end_if##', 
    1 => '', 
    2 => ' 
    First Conditions 
    ##if## 
    First sub Conditions 
    ', 
) 

這是不對的,我需要與##if##
返回內容的開始,並與##end_if##

回答

0

結束,您需要使用preg_match_all代替:

$returnValue = preg_match_all('/##if##(.*?)(.*?)##end_if##/s', '##if## 
    First Conditions 
    ##if## 
    First sub Conditions 
    ##end_if## 
##end_if## 

##if## 
    Second Conditions 
##end_if##', $matches); 

Eval Here

打印:

Array 
(
    [0] => ##if## 
    First Conditions 
    ##if## 
    First sub Conditions 
    ##end_if## 
    [1] => ##if## 
    Second Conditions 
##end_if## 
) 
+0

##,如果## 第一副條件 ## END_IF ##我需要這也是在返回的數組 –