Php 使用preg_match_all将单词置于某组单词的左侧和右侧

Php 使用preg_match_all将单词置于某组单词的左侧和右侧,php,preg-match-all,Php,Preg Match All,我试着用preg_match_all将文本放在某组单词的左右两侧,但它没有按我想象的方式工作。相反,打印或打印出包含某组单词左右两侧文本的数组,而不打印任何内容。我做错了什么 $input = "text1 can you text2"; preg_match_all('(.+?)\s+can you\s+(.+)/i', $input, $matches); print_r($matches); 那么: $input = "text1 can you text2"; $x=explode

我试着用preg_match_all将文本放在某组单词的左右两侧,但它没有按我想象的方式工作。相反,打印或打印出包含某组单词左右两侧文本的数组,而不打印任何内容。我做错了什么

$input = "text1 can you text2";
preg_match_all('(.+?)\s+can you\s+(.+)/i', $input, $matches);

print_r($matches);
那么:

$input = "text1 can you text2";

$x=explode('can you',$input);
print_r($x); //Array ( [0] => text1 [1] => text2 ) 

我有一种强烈的冲动,想对着自己说“哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦;