2012-04-10 52 views
0

我想獲取在文本區域輸入的URL的元標記,這是什麼問題?PHP獲取元標記,URL中的數組= =不工作

此外,我將如何把元描述來自描述的URL?

<form method="get"> 
<textarea name="TAData"> 
</textarea> 
<input type="submit" value="submit"/> 
</form> 

<div id="checkboxes"> 
<input type="checkbox" name="vehicle" value="PR" /> Show me the PR<br /> 
<input type="checkbox" name="vehicle" value="KW Tag" /> Show me the KW tag<br /> 
<input type="checkbox" name="vehicle" value="Title Tag" /> Show me the Title tag<br /> 
</div> 
<div id="checkboxes"> 
<input type="checkbox" name="vehicle" value="1stH1" /> Show me the 1st H1<br /> 
<input type="checkbox" name="vehicle" value="2ndH1" /> Show me the 2nd H1 tag<br /> 
<input type="checkbox" name="vehicle" value="SeedKW" /> Show me Seed KW's<br /> 
</div> 

<div id="nofloat"></div> 

<?php 

//make the array 
$TAarray = explode("\n", strip_tags($_POST['TAData'])); 

var_dump($TAarray); 

//loop through the array 
foreach ($TAarray as $line) { 


    $line = htmlspecialchars(trim($line)); 
}  

    foreach ($TAarray as $url) { 

      // get the meta data for each url 
      $tags = get_meta_tags($url); 

unset($tags["content-type"]); 
unset($tags["page-type"]); 
unset($tags["page-topic"]); 
unset($tags["audience"]); 

       echo '<tr>'; 
       foreach ($tags['description'] as $meta)   
      { 
         echo '<td>' . $meta . '</td>'; 
       } 
       echo '</tr>'; 
     } 
?> 

此外,有沒有辦法只包括元描述?

+2

你檢查'$ _ POST [ 'TAData']'但你的表單方法是'get'。應該是'post'。 – 2012-04-10 16:20:13

+4

即使你是PHP的新手,你可能知道的不僅僅是「不工作」。請在你的問題上付出一些努力。 – 2012-04-10 16:21:01

+0

感謝您的意見,我真的不知道任何其他事情,然後不工作,它顯示沒有錯誤... – RuFFCuT 2012-04-10 16:24:34

回答

1

1)您的表單被聲明爲GET,但您正在讀取$ _POST字段中的值。

2)如果你想只提取「說明」 meta值,你不需要做了標記的迭代,你可以使用:

$description = $tags["description"] 
+0

感謝您的幫助! – RuFFCuT 2012-04-10 16:29:44

+0

腳本現在正在工作,但只有當我走到第二行時,我把一個URL放在文本區域,它給了我錯誤:**爲foreach()**和** [function.get -meta-tags]:php_network_getaddresses:getaddrinfo失敗:名稱或服務未知** – RuFFCuT 2012-04-10 16:31:22

+0

'foreach($ TAarray as $ key =>&$ line){$ line = trim($ line); }' – kuba 2012-04-10 16:36:27