2017-02-18 90 views
-1

我已经验证码我怎样才能捕捉图像画廊的不一系列

但对于这一点,使得像图像的模式[1-10] .jpg文件 ,但我想要的是获取gallley这样上述但也喜欢domain.com/gallery/ 我有什么机会得到这个工作。

希望有人可以打电话给我的tric。

$parts = preg_split("/\[\d+-\d+\]/", $url, -1, PREG_SPLIT_DELIM_CAPTURE); 
preg_match_all("/\[\d+-\d+\]/", $url, $matches, PREG_PATTERN_ORDER); 
$parts_number = count($parts); 
$matches_number = count($matches[0]); 
// JYM 
if ($parts_number==1) { 

    $image_alt_url=$url; 
    $url = str_replace("[", '', $url); 
    $url = str_replace("]", '', $url); 

    $alto = str_replace("/", '_', $image_alt_url); 
    $alto = str_replace("www", '', $alto); 
    $alto = str_replace("http", '', $alto); 
    $alto = str_replace("https", '', $alto); 
    $alto = str_replace("jpg", '', $alto); 
    $alto = str_replace("com", '', $alto); 
    $alto = str_replace("net", '', $alto); 
    $alto = str_replace("info", '', $alto); 
    $alto = str_replace(".com.np", '', $alto); 
    $alto = str_replace("org", '', $alto); 
    $alto = str_replace(".", '', $alto); 
    $alto = str_replace(":_", '', $alto); 
    $alto = str_replace("-", '_', $alto); 
    $alto = preg_replace("/[^a-z-_]/",'',$alto); 
    $alto = str_replace("__", '_', $alto); 
    $alto = str_replace("___", '_', $alto); 
    $alto = str_replace("_", '-', $alto); 
    $alto=substr($alto, 1, -1); 



    $ary_header = get_headers($url, 1); 
    $filesize = $ary_header['Content-Length']; 

回答

0

因为你的问题不提供任何样品的投入,并没有预期的结果,我不得不做出几个假设:

$url="https://www.example.com/gallery/image3.jpg, example.com/gallery/image9.jpg, http://example.com/gallery/image14.JPG"; 
if(!preg_match_all("/([^, ]*\/)([^,]*?(\d+).jpg)/i",$url,$matches,PREG_SET_ORDER)){ 
    echo "No Matches Found"; 
} 
foreach($matches as $match){ 
    list($fullstring,$path,$filename,$id)=$match; 
    echo "<div>fullstring=$fullstring</div>"; 
    echo "<div>path=$path</div>"; 
    echo "<div>filename=$filename</div>"; 
    echo "<div>id=$id</div><br>"; 

    // ...now do any necessary substring processing. 
} 

输出:

fullstring=https://www.example.com/gallery/image3.jpg 
path=https://www.example.com/gallery/ 
filename=image3.jpg 
id=3 

fullstring=example.com/gallery/image9.jpg 
path=example.com/gallery/ 
filename=image9.jpg 
id=9 

fullstring=http://example.com/gallery/image14.JPG 
path=http://example.com/gallery/ 
filename=image14.JPG 
id=14 

通过隔离您希望保留的部分字符串,您可以减少工作负荷。

+0

@cobrax我已经提出了一个非常普遍的答案,可以帮助你。如果您需要进一步指导,请留下评论。让我们将您的问题提供给未来SO读者的某种有用的解决方案。 – mickmackusa

相关问题