Question

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

Was it helpful?

Solution

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"

OTHER TIPS

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!";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top