我需要将URL拆分为数组。
示例:
https://demoURL:44355/test/new/demo.html/#ContactPerson?language=EN
到
array(
'http:/',
'demoURL:44355',
'test/new/demo.html/#ContactPerson?language=EN'
)
preg_split
。
答案 0 :(得分:0)
试一试:
<?php
$body = "https://demoURL:44355/test/new/demo.html/#ContactPerson?language=EN";
$regex = '/((?<=\/)(?=\/))|((?<=\/{2})(?=[A-Za-z]+:[0-9]+))|(?<=[0-9]{1})(?=\/[a-z\/.?=#]+)/';
$url = preg_split($regex, $body);
print_r($url);
?>
你会得到:
Array (
[0] => https:/
[1] => /
[2] => demoURL:44355
[3] => /test/new/demo.html/#ContactPerson?language=EN
)