2013-05-03 61 views
0

我有一個PHP腳本,它可以抓取頁面並提取頁面中的第一張圖片,但這樣做效果不佳,我寧願得到的結果也不是完全模糊的圖片,那麼是否可以修改以下腳本來提取第一個link rel="apple-touch-icon"link rel="apple-touch-icon-precomposed"的通用URL?找到Apple Touch圖標的PHP腳本

<?php 
if($_REQUEST['url']!='') 
{ 
function get($a,$b,$c) 
{ // Gets a string between 2 strings 
$y = explode($b,$a); 
$x = explode($c,$y[1]); 
return $x[0]; 
} 
$url=get_meta_tags("".$_REQUEST['url'].""); 
?> 

<div class="addSitetitle"><?php echo get(file_get_contents(''.$_REQUEST['url'].''), "<title>", "</title"); ?></div> 
<div class="addSitedescription"><?php echo ($url["description"]); ?></div> 
<div class="addSitekeywords"><?php echo ($url["keywords"]); ?></div> 
<div class="addSitecopyright"><?php echo ($url["copyright"]); ?></div> 
<div class="addSiteimage"><img <?php echo get(file_get_contents(''.$_REQUEST['url'].''), "<img", "/>"); ?> /></div> 

被編輯爲包含get函數。

+0

玩得開心* *後處理HTML使用超文本預* *處理器,你有沒有試過'javascript'? – AlexP 2013-05-03 01:17:57

+0

嘿亞歷克斯,說實話,我的部署工作完美無瑕,我只是結束了無關緊要的圖片。如果有人知道如何修改代碼段,那太棒了。 – 2013-05-03 01:19:54

+0

我們需要看函數代碼get()' – hek2mgl 2013-05-03 01:26:58

回答

0

使用this,您可以獲得與代碼鏈接到圖像,如:

$html = file_get_html($url); 
$img = $html->find('img[rel=apple-touch-icon]'); 
echo $img->href; 
+0

請注意,您的simphtmldom的東西是PHP4。 PHP5'hasDOMDocument :: loadHTML()'。起來啊。我在評論 – hek2mgl 2013-05-03 01:45:02

+1

中告訴過你,這不會使我的答案無效,而且是非建設性的。不要成爲一個傻瓜。 – verbumSapienti 2013-05-03 01:51:29

+0

謝謝你的幫助! – 2013-05-03 01:53:55