2

我正在 codeigniter 中使用 TinyMCE 进行内容输入。但是输出源如下所示,不显示 < 和 >。相反,它显示 HTML 实体,如 &lessthan; 并且&大于; 等等

该条目由管理员在登录后进行。

输出来自数据库。

我在模型中取出了逃生,但它仍然做同样的事情。

我还有一个配置设置, $config['global_xss_filtering'] = FALSE;

所以我想添加html_entity_decode。但是 $page_data 是一个数组。该数组具有用于页面项目的 id、title、content 和 slug。

谁能告诉我该怎么做?


输出示例:

&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]);
    }
}
4

2 回答 2

1

如果我正确理解了你,你想通过“html_entity_decode”。到从您的数据库返回的所有字段。您可以轻松地在 fetch 函数中添加一些内容:

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;
}

如果我的问题正确,那应该做你想做的事。

于 2009-10-01T08:53:28.017 回答
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 );
}
于 2011-10-23T20:07:27.660 回答