PHP explode (多)分隔符(delimiters) 使用
-
问题:[https://blog.csdn.net/YBaog?type=blog\]
把链接中所有的字符串取出。
-
㊙️ 神秘算法 ㊙️
php
function multi_explode($delimiters, $string)
{
$data = [];
if ($string) {
$str = str_replace($delimiters, $delimiters[0], $string);
$data = explode($delimiters[0], $str);
$data = array_filter($data);
}
return $data;
}
$text = 'https://blog.csdn.net/YBaog?type=blog';
$needle = [':','//','.','/','?','='];
$split = multi_explode($needle,$text);
- 返回结果
php
array(7) {
[0]=>
string(5) "https"
[2]=>
string(4) "blog"
[3]=>
string(4) "csdn"
[4]=>
string(3) "net"
[5]=>
string(5) "YBaog"
[6]=>
string(4) "type"
[7]=>
string(4) "blog"
}
❓❓❓这个过程是否可逆,童鞋们给点思路啊❗️