-1

I have a link like that: http://adf.ly/2323070/http://www.fileflyer.com/view/O33TOYUAFMIFF

And I want to get only this part of the URL: http://www.fileflyer.com/view/O33TOYUAFMIFF

Note The URL number can be change, so the syntax of the URL is: http://adf.ly/{NUMBERS}/{URL}

How can I parse this URL?

Thanks! and sorry for my English

HTMHell
  • 5,761
  • 5
  • 37
  • 79

2 Answers2

2

A simple regex of #https?://(www\.)?adf\.ly/\d+/(.*)#i should do the trick. This also supports https://adf.ly` (in case it exists) and http://www.adf.ly.

<?php
    $url = "http://‌‌‌‌‌‌"."adf.ly/2323070/http://www.fileflyer.com/view/O33TOYUAFMIFF";
    preg_match("#https?://(www\.)?adf\.ly/\d+/(.*)#i", $url, $matches);
    var_dump($matches[2]);
?>

outputs

string(43) "http://www.fileflyer.com/view/O33TOYUAFMIFF"

Laurel
  • 5,965
  • 14
  • 31
  • 57
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
0

A regexp like #http://adf.ly/(\d+)/(.*)#i should do the trick. For example:

<?php
$theinput = 'http://adf.ly/2323070/http://www.fileflyer.com/view/O33TOYUAFMIFF';
$regexp = '#http://adf.ly/(\d+)/(.*)#i';
if (preg_match($regexp, $theinput, $matches)) {
    echo "Number: " . $matches[1] . "<br>\n";
    echo "URL: " . $matches[2] . "<br>\n";
}
else {
    echo "No match!";
}
Atli
  • 7,855
  • 2
  • 30
  • 43