2011-08-22 175 views
1

我正在使用Wordpress內的發佈模板創建表格。但是格式化有點搞砸了。Wordpress無法正確顯示錶格?

生成代碼的PHP進入並向服務器查詢當天用戶的測試信息。然後它細化內部報告以獲取表格。請注意,報告不會關閉</tbody>標記,所以我必須使用str_replace關閉該標記。

global $current_user; 

get_currentuserinfo(); 

$raw_contents = file_get_contents('http://******/NamedRptRun.asp?Rpt=DailyUserSum&Prj=******_****UserId='.($current_user->user_login)); 

    $trim_raw = trim($raw_contents); 
//echo htmlentities($trim_raw); 

if ($trim_raw == 'No Records Returned') { 

    echo 'No test cases to report today.'; 

} else { 

    $tag = '<TABLE'; 

    $topTrim_contents = stristr($raw_contents, $tag); 

    $tag = '</BODY>'; 

    $table_only = stristr($topTrim_contents, $tag, TRUE); 

    $table_only = str_replace("</tr></table>", "</tbody></tr></table>",$table_only); 

    echo htmlentities($table_only); 
    echo str_replace(array("\r\n","\n","\t"), ' ',$table_only); 

} 

這爲我提供了表格的代碼(僅用於調試目的)以及應該是什麼表格。但是,表格的值實際上並不在表格中,但顯示在表格上方的行中。

<TABLE cellspacing=0 cellpadding=0 border=1 bordercolor=Silver> 
<thead class=b> 
<TR bgColor=WHITE> 
<th>&nbsp;Engineer&nbsp;</th><th>&nbsp;Passed&nbsp;</th><th>&nbsp;PWWarn&nbsp;</th><th>&nbsp;Blocked&nbsp;</th><th>&nbsp;Failed&nbsp;</th><th>&nbsp;Total Run&nbsp;</th></tr></thead><tbody class=h><TR bgColor=#F1F1F1><TD nowrap>myname</td><TD nowrap>1</td><TD nowrap>0</td><TD nowrap>0</td><TD >0</td><TD nowrap>1</td></tbody></tr></table> 

10001 
Engineer Passed  PWWarn  Blocked  Failed  Total Run 
myname 

任何人有任何建議,爲什麼會發生這種情況?

粘貼查看頁面生成的最終表格的來源。

<table border="1" cellspacing="0" cellpadding="0"> 
    <thead class="b"> 
     <tr bgcolor="WHITE"> 
      <th> Engineer</th> 
      <th> Passed</th> 
      <th> PWWarn</th> 
      <th> Blocked</th> 
      <th> Failed</th> 
      <th> Total Run</th> 
     </tr> 
    </thead> 
    <tbody class="h"> 
     <tr bgcolor="#F1F1F1"> 
      <td nowrap="nowrap">myname</td> 
     </tr> 
    </tbody> 
</table> 
+0

對於初學者,您的結束''和''標記是錯誤的方式。另外,您使用的是哪種瀏覽器?可能會幫助我重現問題... –

+0

我正在使用最新版本的Firefox和Chrome。我也運行Wordpress 3.2.1,有趣的是,它在3.1中正常工作。 –

+0

那麼,你的HTML - 甚至你的原始版本;我只是把它粘貼 - 在WordPress 3.2.1的帖子中呈現給我。也許你的主題CSS或插件或其他東西是搗毀的東西? –

回答

0

解決方法是在聯繫作者SimplePostTemplate後發現的。似乎wordpress會過濾出不好的HTML,這正是它對我的表格所做的,因此它爲什麼沒有正確顯示。

我能夠讓其他部門在wordpress之前清理它們的html,從而通過過濾器並解決問題。