0

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.

gofr1
  • 15,741
  • 11
  • 42
  • 52
  • what have you tried? http://stackoverflow.com/questions/11480763/how-to-get-parameters-from-this-url-string – MarZab Sep 25 '16 at 09:11
  • 1
    Why dont you just use the `parse_url` function? http://php.net/manual/en/function.parse-url.php – GeorgeQ Sep 25 '16 at 09:12

1 Answers1

0

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 
)