How to get only id from url

I have thousands of URLs that have identifiers that I want to get only from the URL, for example This is my array

Array
(
    [0] => http://www.videoweed.es/file/f62f2bc536bad
    [1] => http://www.movshare.net/video/5966fcb2605b9
    [2] => http://www.nowvideo.sx/video/524aaacbd6614
    [3] => http://vodlocker.com/pbz4sr6elxmo
)

I want the identifiers from the links above.

f62f2bc536bad

5966fcb2605b9

524aaacbd6614

pbz4sr6elxmo

I have a function parse_url, but it returns me path, which includes all things after the slash (/), for example / file / pbz4sr6elxmo

<?php 
foreach($alllinks as $url){
  $parse = parse_url($url);
  echo $parse['path'];
}
?>

Output

/ pbz4sr6elxmo

/ video / 5966fcb2605b9

/ File / f62f2bc536bad

/ video / 524aaacbd6614

+4
source share
3 answers

You can try with explode-

$alllinks = array
(
    'http://www.videoweed.es/file/f62f2bc536bad',
    'http://www.movshare.net/video/5966fcb2605b9',
    'http://www.nowvideo.sx/video/524aaacbd6614',
    'http://vodlocker.com/pbz4sr6elxmo'
);

foreach($alllinks as $url){
  $temp = explode('/', $url);
  echo $temp[count($temp) - 1].'<br/>';
}

Output

f62f2bc536bad
5966fcb2605b9
524aaacbd6614
pbz4sr6elxmo

This will only help if the structure urlis the same, i.e. the last part isid

+6
source

URL- ,

$url = 'http://www.videoweed.es/file/f62f2bc536bad';
$url_split = explode('/', $url);
$code = $url_split[count($url_split) - 1];
+3

:

$alllinks = array(
    'http://www.videoweed.es/file/f62f2bc536bad',
    'http://www.movshare.net/video/5966fcb2605b9',
    'http://www.nowvideo.sx/video/524aaacbd6614',
    'http://vodlocker.com/pbz4sr6elxmo'
);

foreach($alllinks as $url){
  $parts = explode('/', $url);
  echo end($parts).'<br/>';
}
0

All Articles