这是一个提取您要查找的内容的函数。
function getTheStuff($url) {
// Only get the part of the URL that
// actually matters; this makes the
// problem smaller and easier to solve
$path = parse_url($url, PHP_URL_PATH);
// The path will be false if the URL is
// malformed, or null if it was not found
if ($path !== false && $path !== null) {
// Assuming that the stuff you need is
// always after the first forward slash,
// and that the format never changes,
// it should be easy to match
preg_match('/^\/[\d_]+\/(\d+\/\d+)/', $path, $result);
// We only capture one thing so what we
// are looking for can only be the second
// thing in the array
if (isset($result[1])) {
return $result[1];
}
}
// If it is not in the array then it
// means that it was not found
return false;
}
$url = 'http://movies.actionpaxed.com/5600_5949/5943/5/pics/none/500k/3min/003.jpg?nvb=20130811232301&nva=20130812012301&hash=090a687f7e27b2f5ef735';
var_dump(getTheStuff($url));
如果我是为自己写这个,那么我会避免使用正则表达式。在这种情况下它是最简单的,所以我使用了它。我可能会通过标记$path
(/
用作分隔符)来概括解决方案,然后让另一个函数/方法/机制处理提取所需的部分。这样一来,其他格式不同的 URL 会更容易采用它。