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,444
  • 11
  • 42
  • 49

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 
)