使用 preg_match_all 获取某组单词左侧和右侧的单词
Getting words to the left and right of a certain group of words using preg_match_all
我正在尝试使用 preg_match_all 将文本添加到特定单词组的左侧和右侧,但它并没有像我想象的那样工作。相反 print_r 打印出包含特定单词组左右两侧文本的数组,它什么也没有打印出来。我做错了什么?
$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 )
我正在尝试使用 preg_match_all 将文本添加到特定单词组的左侧和右侧,但它并没有像我想象的那样工作。相反 print_r 打印出包含特定单词组左右两侧文本的数组,它什么也没有打印出来。我做错了什么?
$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 )