PHP preg_split 函数是否带连字符?
phpserver side programmingprogramming更新于 2025/8/18 3:22:17
在 PHP 中使用 preg_split() 函数并使用连字符进行拆分。假设我们的输入值包含数字和字符串,并用连字符分隔。
$values = "ABC-DEF IJKL-3553435-8990987876";
我们希望输出结果为:
Array ( [0] => ABC-DEF IJKL [1] => 3553435 [2] => 8990987876 )
示例
PHP 代码如下
<!DOCTYPE html>
<html>
<body>
<?php
$values ="ABC-DEF IJKL-3553435-8990987876";
$exploded = preg_split('/-(?=[0-9])/', $values, 3);
print_r($exploded);
?>
</body>
</html>
输出
This will produce the following output
Array ( [0] => ABC-DEF IJKL [1] => 3553435 [2] => 8990987876 )

