I need to split a URL into an array.
Example:
https://demoURL:44355/test/new/demo.html/#ContactPerson?language=EN
to
array(
'http:/',
'demoURL:44355',
'test/new/demo.html/#ContactPerson?language=EN'
)
with preg_split
.
I need to split a URL into an array.
Example:
https://demoURL:44355/test/new/demo.html/#ContactPerson?language=EN
to
array(
'http:/',
'demoURL:44355',
'test/new/demo.html/#ContactPerson?language=EN'
)
with preg_split
.
Try it:
<?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);
?>
You'll get:
Array (
[0] => https:/
[1] => /
[2] => demoURL:44355
[3] => /test/new/demo.html/#ContactPerson?language=EN
)