在 pdf 扩展中找到链接 [英] find link in pdf extension

查看:23
本文介绍了在 pdf 扩展中找到链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取带有 pdf 扩展名的链接.我的代码是:

i need to get links with pdf extension. my code is :

<?php

set_time_limit (0);
curl_setopt($ch, CURLOPT_URL,"http://example.com");
curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

preg_match_all( '/<a href="(http:\/\/www.[^0-9].+?)"/', $result, $output, PREG_SET_ORDER); // read all links

foreach($output as $item  ){ 
    $n=strlen($item);
    $m=$n-3;
    $buffer_n=$item;
    $buffer_m="";
    $buffer_m=$buffer_n[$m].$buffer_n[$m+1].$buffer_n[$m+2];
    $ekstension = 'pdf';
        if ($buffer_m == $ekstension) {
           print_r($item);
           echo '<br>';
         }
}

?>

代码给我空白结果,我的代码有什么问题?非常感谢:)

the code give me blank result, what's wrong with my code? thank you very much :)

推荐答案

用简单的html dom解决,代码为:

solved using with simple html dom, the code is :

<?php

set_time_limit(0);
include 'simple_html_dom.php';
$url = 'example';
$html = file_get_html($url) or die ('invalid url');

foreach($html->find('a') as $e) {
    $link= $e->href;
    if (preg_match('/\.pdf$/i', $link)) {
    }
}

print_r($result);

?>

这篇关于在 pdf 扩展中找到链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆