为此,请使用preg_match_all()。假设以下是我们的字符串
$values = 'javamysqlphpmongodbpythonspringhibernatephp';
我们想用诸如
java hibernate php
PHP代码如下
<!DOCTYPE html> <html> <body> <?php $values = 'javamysqlphpmongodbpythonspringhibernatephp'; $afterSpliting = preg_match_all("/(java|hibernate|php)/", $values, $result); print_r($result); ?> </body> </html>
输出结果
这将产生以下输出
Array ( [0] => Array ( [0] => java [1] => php [2] => hibernate [3] => php ) [1] => Array ( [0] => java [1] => php [2] => hibernate [3] => php ) )