-1

I have url like https://in.pinterest.com/sridharposnic/restinpeace/. I want url directories without domain in php array. Example:-

$array[0] = 'sridharposnic';
$array[1] = 'restinpeace';

How we can extract these ?

Bala
  • 913
  • 9
  • 18

1 Answers1

1

You can use parse_url() and explode():

$url = 'https://in.pinterest.com/sridharposnic/restinpeace/';
$parsed = parse_url( $url );
$chunks = explode( '/', trim($parsed['path'],'/') );
print_r( $chunks );

Will print:

Array
(
    [0] => sridharposnic
    [1] => restinpeace
)
fusion3k
  • 11,568
  • 4
  • 25
  • 47