2009-09-28 169 views
2

我正在用codeigniter中的TinyMCE進行內容輸入。 但是,輸出源如下所示,不顯示<和>。相反,它顯示HTML內容像&lessthan;和&greaterthan;等等。如何將html_entity_decode添加到數組中?

該條目由管理員登錄後提出。

輸出來自數據庫。

我拿出模特逃跑,但它仍然做同樣的事情。

另外我有一個配置設置,$ config ['global_xss_filtering'] = FALSE;

所以我想添加html_entity_decode。但$ page_data是一個數組。 該數組具有用於頁面項目的標識,標題,內容和slu g。

請問誰能告訴我該怎麼做?


輸出例如:

&lt;p&gt;&lt;img src=&quot;images/icon1.png&quot; border=&quot;0&quot; 
alt=&quot;icon&quot; width=&quot;48&quot; height=&quot;48&quot; /&gt; 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 

型號代碼:

<?php 

class Pagemodel extends Model 
{ 
.... 
... 

/** 
* Return an array of a page — used in the front end 
* 
* @access public 
* @param string 
* @return array 
*/ 
function fetch($slug) 
{ 
    $query = $this->db->query("SELECT * FROM `pages` WHERE `slug` = '$slug'"); 
    return $query->result_array(); 
} 


... 
... 

} 

?> 

控制器代碼:

function index() 
{ 
    $page_slug = $this->uri->segment('2'); // Grab the URI segment 

    if($page_slug === FALSE) 
    { 
     $page_slug = 'home'; 
    } 

$page_data = $this->pages->fetch($page_slug); // Pull the page data from the database 

    if($page_data === FALSE) 
    { 
     show_404(); // Show a 404 if no page exists 
    } 
    else 
    { 
     $this->_view('index', $page_data[0]); 
    } 
} 
+0

哪裏輸出從何而來?從數據庫?或者從你的觀點來看? – Natrium 2009-09-28 06:43:48

+0

小心抑制轉換;它在那裏是爲了您的保護。 – 2009-09-28 07:18:58

+0

@Natrium:它來自數據庫,我添加了模型。 @Jonathan:正如我在原文中添加的,登錄後登錄完成,所以應該沒問題。 – shin 2009-09-28 07:50:05

回答

1

如果我找到了你,你想通過'html_entity_decode'。到數據庫返回的所有字段。您可以輕鬆地添加一些你的抓取功能:

function fetch($slug) 
{ 
    $query = $this->db->query("SELECT * FROM `pages` WHERE `slug` = '$slug'"); 
    for($i=0; $i<$query->num_rows(); $i++) 
    { 
     $html_decoded[$i]['id'] = html_entity_decode($query->id); 
     $html_decoded[$i]['title'] = html_entity_decode($query->title); 
     $html_decoded[$i]['content'] = html_entity_decode($query->content); 
     $html_decoded[$i]['slug'] = html_entity_decode($query->slug); 
    } 

    return $html_decoded; 
} 

如果我得到你應該做你想要什麼你的問題的權利。

0

如果你喜歡避免對結果集騎自行車,你可以使用的

array_map() 

設施,做這樣的事情:

function fetch($slug) 
{ 
    $query = $this->db->query("SELECT * FROM `pages` WHERE `slug` = '$slug'"); 
    return array_map(array($this, decodearray), $query->result_array()); 
} 

function decodearray($myarray){ 
    return html_entity_decode($myarray,ENT_QUOTES); 
}