1

Hi all hope this makes sense.

I am wondering if there is a way to split the following with php

so

$url = "http://50.7.71.219:7183/listen.mp3";

I then need to split it into 2 more strings so i should get a result of :

$ip = "http://50.7.71.219";
$port = "7183";

Thanks, Jamie

Rabbi Shuki Gur
  • 1,656
  • 19
  • 36

2 Answers2

3

There is actually a built in way of doing this in PHP. Use the parse_url function. This method also returns a host of other information that could be useful, click here to learn more.

<?php

$url = "http://50.7.71.219:7183/listen.mp3";
$parsedUrl = parse_url($url);
$ip = $parsedUrl['host'];
$port = (string) $parsedUrl['port'];

echo $ip . "<br />" . $port;

?>
Neil
  • 14,063
  • 3
  • 30
  • 51
1
$s1=explode($url,":");
$s2=explode($s1[2],"/");
$ip=$s1[0].':'.$s1[1];
$port=$s2[0];

This should do the trick.