Php 如何提取两个字符之间的短语?

Php 如何提取两个字符之间的短语?,php,Php,我想使用正则表达式从上面的$string中导出由{}符号覆盖的字符串 我尝试使用substr,但它只出现了第一次 我已经完全开始学习PHP了 请帮助我。使用此: $string="Quick {brown fox jump} over the {lazy dog.}Go back to the forest"; 输出: $string="Quick {brown fox jump} over the {lazy dog.}Go back to the forest"; preg_match_a

我想使用正则表达式从上面的
$string
中导出由{}符号覆盖的字符串 我尝试使用
substr
,但它只出现了第一次 我已经完全开始学习PHP了 请帮助我。

使用此:

$string="Quick {brown fox jump} over the {lazy dog.}Go back to the forest";
输出:

$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

您可以使用preg_match_all来提取序列。
Array
(
    [0] => brown fox jump
    [1] => lazy dog.
)