preg_match list of urls without spaces
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
)
精彩评论