如何提取2个字符之间的短语php?

时间:2015-06-20 16:03:02

标签: php

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

我希望使用正则表达式从$string上方用{}符号覆盖字符串 我尝试使用substr,但它只给我第一次出现 我完全熟悉PHP 请帮帮我..

1 个答案:

答案 0 :(得分: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.
)