2012-04-11 77 views
0

我希望把我的PHP輸出到一個表,但它不喜歡它...對外輸出PHP插入到HTML表格

我想要的佈局是這樣的

ROW - Desctiption URL ROW2 - 元描述

即使輸入多個URL,也需要保持相同的佈局。

現在發生的事情是,當我輸入大量的網址時,它將所有相同的部分放到同一個單元格中。我怎樣才能改變它?

對不起它很難解釋......

下面是代碼:

<?php 
ini_set("display_errors", 0); 
//make the array 
$TAarray = explode("\n", strip_tags($_POST['TAData'])); 

foreach ($TAarray as $key => &$line) { 
     $line = trim($line); 
     // get the meta data for each url 
     $tags = get_meta_tags($line); 

     echo '<tr>'; 
     echo (isset($tags['description']))?"<tr><td>Description($line)</td> </tr>".$tags['description']:"<tr><td>Description($line)</td></tr><tr><td>No Meta Description</td></tr>."; 
     echo '</tr>'; 
} 

?> 
+2

也許'

'標記丟失? – 2012-04-11 12:53:09

回答

1

你有一些尷尬的HTML有..嘗試做這樣的:

//start the table 
echo "<table>"; 
foreach ($TAarray as $key => &$line) { 
     $line = trim($line); 
     // get the meta data for each url 
     $tags = get_meta_tags($line); 

     //start a new row in the table 
     echo '<tr>'; 
     if(isset($tags['description'])){ 
      //add two cells to the table. 
      echo "<td>Description($line)</td>"; 
      echo "<td>{$tags['description']}</td>"; 
     } else { 
      echo "<td>Description($line)</td>" 
      echo "<td>No Meta Description</td>"; 
     } 
     echo '</tr>'; 
} 
echo "</table>"; 
0
//make the array 
$data='http://stackoverflow.com 
http://ebay.com/'; 
$TAarray = explode("\n", strip_tags($data)); 
echo "<table>"; 
foreach ($TAarray as $key => &$line) { 
     $line = trim($line); 
     // get the meta data for each url 
     $tags = get_meta_tags($line); 

     echo '<tr>'; 
     if(isset($tags['description'])){ 

     echo "<tr><td>Description($line):".$tags['description']:" </td> "; else{ 

      "</tr><tr><td>Description($line)</td></tr><tr><td>No Meta Description</td></tr>."; 
     echo '</tr>'; 
     } 
} 
echo "</table>";