我想找到两个字符之间的文字
$var ='J111 king Jadv oops J123 php';
在上面的变量中,我只得到从J开始的字母。
我需要以下输出,
将J值作为
启动Array ( [0] =>J111 [1] => Jadv [2] => J123)
并将值平衡为,
Array ( [0] =>king [1] => oops [2] => php)
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以尝试:
$var ='J111 king Jadv oops J123 php';
//get all the words in array
$words = preg_split('/\s+/', $var);
//match all the words starting with letter J
preg_match_all('(J[^\s]+)', $var, $matches);
//words with matching letter
$words_with_letter = $matches[0];
//words without matching letter
$words_without_letter = array_values(array_diff($words,$words_with_letter));
希望这有助于你:)