小编Leo*_*one的帖子

正则表达式:显示所有电话号码

我想查看我的字符串中的所有电话号码.现在它在数组'匹配'中只有一个数字我怎么能得到我的数组中的所有数字?

$str = "djvdsfhis 0647382938 rdfrgfdg tel:0647382938 rfgdfgfd 06 47 38 29 
38 fdgdfrggfd tel:06-47382938 cxgvfdgsfdc";
$arr = '~\d{2}-\d{8}|\d{10}~';
$success = preg_match($arr, $str, $match);
if ($success) {
    echo "Match: ".$match[0]."<br />"; 
    print_r($match);
}
Run Code Online (Sandbox Code Playgroud)

我得到这个作为输出:

djvdsfhis ffgfg 0647382938 rdfrgfdg tel:0647382938 rfgdfgfd 06 47 38 29 38 fdgdfrggfd tel:06-47382938 cxgvfdgsfdc

Match: 0647382938
Array ( [0] => 0647382938 )
Run Code Online (Sandbox Code Playgroud)

但我想让我的数组像这样:

Array ( [0] => 0647382938 [1] => 0647382938 [2] => 06-47382938
Run Code Online (Sandbox Code Playgroud)

php regex

3
推荐指数
1
解决办法
69
查看次数

标签 统计

php ×1

regex ×1