Preg_match不带空格的url列表


preg_match list of urls without spaces

我有这个url列表:

http://test1.google.com/test1/12345http://test2.google.com/test2/12345http://test3.google.com/test4/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345

这只是一个例子,我想preg_match_all一个有效的url列表,没有空间来分隔它们,所以,我会得到它在一个数组中,每个单元格是不同的url。

不需要preg_match:

<?php
$links = 'http://test1.google.com/test1/12345http://test2.google.com/test2/12345http://test3.google.com/test4/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345http://test1.google.com/test1/12345';
$links = array_map(function($chunk){return 'http://'.$chunk;}, explode('http://', $links));
array_shift($links);
print_r($links);

演示,输出:

Array
(
    [0] => http://test1.google.com/test1/12345
    [1] => http://test2.google.com/test2/12345
    [2] => http://test3.google.com/test4/12345
    [3] => http://test1.google.com/test1/12345
    [4] => http://test1.google.com/test1/12345
    [5] => http://test1.google.com/test1/12345
    [6] => http://test1.google.com/test1/12345
    [7] => http://test1.google.com/test1/12345
)