2015-06-20 40 views
0
$string="Quick {brown fox jump} over the {lazy dog.}Go back to the forest"; 

我想exatract字符串,通過{}符號覆蓋,從上面$string,使用正則表達式 我試着用substr,但它只是給我的第一次出現 我完全地beginer到PHP 請幫幫我..如何提取2個字符php之間的短語?

+0

您可以使用preg_match_all來提取序列。 – chris85

回答

0

使用此:

$string="Quick {brown fox jump} over the {lazy dog.}Go back to the forest"; 
preg_match_all('/{([^}]+)}/',$string, $matches); 
print_r($matches[1]);//$matches[1] contains array of all the matches in parenthesis 

輸出:

Array 
(
    [0] => brown fox jump 
    [1] => lazy dog. 
) 
相關問題