开发者

preg_match list of urls without spaces

开发者 https://www.devze.com 2023-03-18 17:17 出处:网络
I have this list of urls: 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/开发

I have this list of urls:

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

It's just an example, I want to preg_match_all a list of valid urls that doesn't have space to seperate between them, so, I will get it in an array and each cell is different url.


No need for preg_match IMHO:

<?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);

Demo, Output:

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
)
0

精彩评论

暂无评论...
验证码 换一张
取 消