Php 如何插入<;的href;a>;在变量内标记并按curl下载?

Php 如何插入<;的href;a>;在变量内标记并按curl下载?,php,curl,hyperlink,download,Php,Curl,Hyperlink,Download,我正在尝试将页面保存为html文档到主机,并通过PHP打开它&下载一些链接(例如&) 给我自己的主人。 一切都很好,除了我想把标签的属性放到变量中的部分 我使用一个函数通过curl下载链接。当我直接插入下载链接时,它可以正常工作,但在我的代码中,href在变量中没有“” 然后下载一个0kb的文件 在这里你可以看到代码和我的解释 <!doctype html> <html> <head> <meta charset="utf-8"> <

我正在尝试将页面保存为html文档到主机,并通过PHP打开它&下载一些链接(例如&) 给我自己的主人。 一切都很好,除了我想把标签的属性放到变量中的部分

我使用一个函数通过curl下载链接。当我直接插入下载链接时,它可以正常工作,但在我的代码中,href在变量中没有“” 然后下载一个0kb的文件

在这里你可以看到代码和我的解释

 <!doctype html>
 <html>
 <head>
 <meta charset="utf-8">
 </head>
 <body>
 <?php
 include ("simple_html_dom.php"); // sourceforge html dom

 $host= " ";  // no need
 $target = "http://example.com/?p=17977";  // target page


 // to save page as html

function gethtm($urlm) {
$url  = $urlm;
$time = time() + rand();
$patha = 'html/temp-html.html';

$fp = fopen($patha, 'w');

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_FILE, $fp);

$data = curl_exec($ch);

curl_close($ch);

fclose($fp);
  }

// download the link

 function downloadurl ($urlf) {

    $url  = $urlf;
$path = 'file/temp.apk';


$ch = curl_init($url);
if($ch === false)
{
        die('Failed to create curl handle');
}

$fp = fopen($path, 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);

$data = curl_exec($ch);

curl_close($ch);
fclose($fp);

}
// save trget
 gethtm($target);

// find download link   
$html = file_get_html('html/temp-html.html');
foreach($html->find('a') as $element ) {

    if( strpos($element->href , 'http://dl2.packdl') !== false) {

        $linka = $element->href;
      }
   }
echo $linka;

/*   here is where u can see my problem if i insert download link myself it
    download it and works
   but does not work by  $linka !
   i tried this values ---->   $linka   '"'.$linka.'"'     "'".$linka."'"   '.$linka.'
also tried this values inside of function but everytime it return 0kb file
but if i insert download link :  "http://example.com/file.rar"   
it works and download file ...  
 that's my question how to download link inside $linka ?

*/
 downloadurl('"'.$linka.'"');

 ?>
  </body>
  </html> 


gf()
的功能是什么?非常确定的是,你根本不需要在这个字符串周围加引号,除非这个函数
gf()
有一个非常不寻常的实现。gf()使用curl下载链接源代码。然后请发布这个函数的实现,我们猜不到。是的,很抱歉你调用了
curl\u init()
两次,为什么?