2009-09-28 171 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); 
}